Skip to content

Commit

Permalink
feat(typescript): fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
srod committed Dec 5, 2022
1 parent 7977338 commit 975758c
Show file tree
Hide file tree
Showing 33 changed files with 1,321 additions and 1,973 deletions.
3 changes: 1 addition & 2 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
"env": {
"node": true,
"es6": true,
"jasmine": true,
"jest": true
"jasmine": true
},
"plugins": ["prettier"],
"extends": ["eslint:recommended", "prettier"],
Expand Down
14 changes: 0 additions & 14 deletions .github/dependabot.yml

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ jobs:
run: pnpm install --no-frozen-lockfile

- name: Run tests
run: pnpm run setup && pnpm test
run: pnpm test
env:
CI: true

Expand Down
16 changes: 0 additions & 16 deletions jest.config.ts

This file was deleted.

14 changes: 5 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,12 @@
},
"packageManager": "pnpm@7.18.0",
"scripts": {
"setup": "npm run clean:packages && npm run build",
"build": "npm run clean:build && npm run build-js",
"build-js": "pnpm lerna exec --parallel -- babel --root-mode upward src --out-dir lib --copy-files",
"build": "lerna run build",
"eslint": "eslint --ignore-path .gitignore packages",
"lerna": "lerna",
"lint": "npm run eslint || true",
"pretest": "npm run build && npm run eslint",
"test": "jest",
"test": "vitest run --coverage",
"posttest": "npm run clean:coverage",
"clean:build": "pnpm dlx rimraf packages/*/lib",
"clean:coverage": "pnpm dlx rimraf tests/tmp/*.{js,js.map,css,html}",
Expand Down Expand Up @@ -54,21 +52,19 @@
"@node-minify/uglify-js": "workspace:*",
"@node-minify/utils": "workspace:*",
"@node-minify/yui": "workspace:*",
"@types/jest": "29.2.3",
"@types/node": "18.11.10",
"@vitest/coverage-c8": "0.25.3",
"eslint": "8.29.0",
"eslint-config-prettier": "8.5.0",
"eslint-plugin-prettier": "4.2.1",
"husky": "8.0.2",
"jest": "29.3.1",
"lerna": "6.1.0",
"lint-staged": "13.1.0",
"node-notifier": "10.0.1",
"prettier": "2.8.0",
"rimraf": "3.0.2",
"ts-jest": "29.0.3",
"ts-node": "10.9.1",
"typescript": "4.9.3"
"typescript": "4.9.3",
"vitest": "0.25.3"
},
"lint-staged": {
"*.js": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
* MIT Licensed
*/

import babelMinify from '../src/babel-minify';
import { describe } from 'vitest';
import babelMinify from '../src';
import { runOneTest, tests } from '../../../tests/fixtures';

const compressorLabel = 'babel-minify';
Expand Down
3 changes: 2 additions & 1 deletion packages/babel-minify/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
"babel-preset-minify": "0.5.2"
},
"devDependencies": {
"@types/babel-core": "^6.25.7"
"@types/babel-core": "^6.25.7",
"babel-preset-env": "1.7.0"
}
}
45 changes: 0 additions & 45 deletions packages/clean-css/__tests__/clean-css.test.js

This file was deleted.

47 changes: 47 additions & 0 deletions packages/clean-css/__tests__/clean-css.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*!
* node-minify
* Copyright(c) 2011-2022 Rodolphe Stoclin
* MIT Licensed
*/

import { afterAll, beforeAll, describe, expect, test } from 'vitest';
import minify from '../../core/src';
import cleanCss from '../src';
import { filesCSS } from '../../../tests/files-path';
import { runOneTest, tests } from '../../../tests/fixtures';

const compressorLabel = 'clean-css';
const compressor = cleanCss;

describe('Package: clean-css', () => {
tests.commoncss.forEach(options => {
runOneTest({ options, compressorLabel, compressor });
});
tests.commoncss.forEach(options => {
runOneTest({ options, compressorLabel, compressor, sync: true });
});
test('should compress with some options', () =>
new Promise(done => {
const options = {};
options.minify = {
compressor,
input: filesCSS.fileCSS,
output: filesCSS.fileCSSOut,
options: {
sourceMap: {
filename: filesCSS.fileCSSSourceMaps,
url: filesCSS.fileCSSSourceMaps
}
}
};

options.minify.callback = (err, min) => {
expect(err).toBeNull();
expect(min).not.toBeNull();

done();
};

minify(options.minify);
}));
});
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@
* MIT Licensed
*/

jest.setTimeout(30000);

import { afterAll, beforeAll, describe, expect, test, vi } from 'vitest';
import childProcess from 'child_process';
import * as cli from '../src/cli';
import * as cli from '../src';
import { filesJS } from '../../../tests/files-path';

describe('Package: cli', () => {
test('should minify to have been called with gcc', () => {
const spy = jest.spyOn(cli, 'run');
const spy = vi.spyOn(cli, 'run');
return cli
.run({
compressor: 'google-closure-compiler',
Expand All @@ -26,13 +25,13 @@ describe('Package: cli', () => {

describe('cli error', () => {
beforeAll(() => {
let spy = jest.spyOn(childProcess, 'spawn');
let spy = vi.spyOn(childProcess, 'spawn');
spy.mockImplementation(() => {
throw new Error();
});
});
test('should minify to throw with yui error', () => {
const spy = jest.spyOn(cli, 'run');
const spy = vi.spyOn(cli, 'run');
const options = {
compressor: 'yui',
input: filesJS.oneFile,
Expand All @@ -42,6 +41,6 @@ describe('cli error', () => {
return cli.run(options).catch(() => expect(spy).toHaveBeenCalled());
});
afterAll(() => {
jest.restoreAllMocks();
vi.restoreAllMocks();
});
});
}, 30000);
6 changes: 4 additions & 2 deletions packages/cli/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ interface Cli {
output: string;
// option: Options;
option: string;
silence: boolean;
silence?: boolean;
}

export interface Result {
Expand All @@ -48,7 +48,9 @@ let silence = false;
*/
const runOne = (cli: Cli): Promise<Result> => {
return new Promise<Result>((resolve, reject) => {
const compressor = typeof cli.compressor === 'string' ? require(`@node-minify/${cli.compressor}`) : cli.compressor;
const compressor =
typeof cli.compressor === 'string' ? require(`@node-minify/${cli.compressor}`).default : cli.compressor;

const options: Settings = {
compressorLabel: cli.compressor,
compressor,
Expand Down
Loading

0 comments on commit 975758c

Please sign in to comment.