Skip to content

Commit

Permalink
test: migrate to built-in Node.js test runner
Browse files Browse the repository at this point in the history
  • Loading branch information
ludofischer committed Apr 27, 2024
1 parent f5d6f33 commit 78c6be5
Show file tree
Hide file tree
Showing 99 changed files with 317 additions and 454 deletions.
7 changes: 3 additions & 4 deletions package.json
Expand Up @@ -6,10 +6,10 @@
"fixlint": "prettier --write . && pnpm lint -- --fix",
"build:integration": "node ./util/buildFrameworks.mjs",
"pretest": "pnpm lint",
"test:only": "uvu packages \"test.*\\.js$\"",
"test:only": "node --test \"packages/**/test/**/*js\"",
"test:coverage": "c8 pnpm test:only",
"test": "pnpm test:coverage",
"test:helpers": "uvu packages \"test.*\\.mjs$\"",
"test:helpers": "node --test \"packages/**/test/**/*mjs\"",
"types": "tsc -b",
"all-publish": "pnpm changeset publish"
},
Expand All @@ -29,8 +29,7 @@
"postcss": "^8.4.38",
"postcss-font-magician": "^4.0.0",
"prettier": "^3.2.5",
"typescript": "~5.4.5",
"uvu": "^0.5.6"
"typescript": "~5.4.5"
},
"browserslist": {
"production": [
Expand Down
3 changes: 1 addition & 2 deletions packages/cssnano-preset-advanced/test/autoprefixer.js
@@ -1,5 +1,5 @@
'use strict';
const { test } = require('uvu');
const { test } = require('node:test');
const {
processCSSWithPresetFactory,
} = require('../../../util/integrationTestHelpers.js');
Expand Down Expand Up @@ -38,4 +38,3 @@ test(
'should not remove outdated vendor prefixes if excluded',
exclude('h1{-webkit-box-sizing:content-box;box-sizing:content-box}')
);
test.run();
7 changes: 3 additions & 4 deletions packages/cssnano-preset-advanced/test/integrations.js
@@ -1,7 +1,7 @@
'use strict';
const { join } = require('path');
const { test } = require('uvu');
const assert = require('uvu/assert');
const { test } = require('node:test');
const assert = require('node:assert/strict');
const {
integrationTests,
loadPreset,
Expand Down Expand Up @@ -51,11 +51,10 @@ function excludeProcessor(options) {
loadPreset(preset(options))
.process(input, { from: undefined })
.then(({ css }) => {
assert.is(css, input);
assert.strictEqual(css, input);
});
}

test('exclude zindex', excludeProcessor({ zindex: false }));

test('exclude zindex #1', excludeProcessor({ zindex: { exclude: true } }));
test.run();
@@ -1,5 +1,5 @@
'use strict';
const { test } = require('uvu');
const { test } = require('node:test');
const {
processCSSWithPresetFactory,
} = require('../../../util/integrationTestHelpers.js');
Expand Down Expand Up @@ -149,4 +149,3 @@ test(
'a{border:0;border-top:3px solid}'
)
);
test.run();
7 changes: 3 additions & 4 deletions packages/cssnano-preset-default/test/integrations.js
@@ -1,7 +1,7 @@
'use strict';
const { join } = require('path');
const { test } = require('uvu');
const assert = require('uvu/assert');
const { test } = require('node:test');
const assert = require('node:assert/strict');
const {
integrationTests,
loadPreset,
Expand Down Expand Up @@ -45,11 +45,10 @@ function excludeProcessor(options) {
loadPreset(preset(options))
.process(input, { from: undefined })
.then(({ css }) => {
assert.is(css, input);
assert.strictEqual(css, input);
});
}

test('exclude colormin', excludeProcessor({ colormin: false }));

test('exclude colormin #1', excludeProcessor({ colormin: { exclude: true } }));
test.run();
3 changes: 1 addition & 2 deletions packages/cssnano-preset-lite/test/index.js
@@ -1,5 +1,5 @@
'use strict';
const { test } = require('uvu');
const { test } = require('node:test');
const {
processCSSWithPresetFactory,
} = require('../../../util/integrationTestHelpers.js');
Expand Down Expand Up @@ -64,4 +64,3 @@ test(
''
)
);
test.run();
3 changes: 1 addition & 2 deletions packages/cssnano-preset-lite/test/integrations.js
@@ -1,10 +1,9 @@
'use strict';
const { test } = require('uvu');
const { test } = require('node:test');
const { integrationTests } = require('../../../util/integrationTestHelpers.js');
const preset = require('..');

test(
'should correctly handle the framework tests',
integrationTests(preset, `${__dirname}/integrations`)
);
test.run();
7 changes: 3 additions & 4 deletions packages/cssnano-utils/test/getArguments.test.js
@@ -1,13 +1,13 @@
'use strict';
const { test } = require('uvu');
const assert = require('uvu/assert');
const { test } = require('node:test');
const assert = require('node:assert/strict');
const valueParser = require('postcss-value-parser');
const getArguments = require('../src/getArguments.js');

test('should get arguments', () => {
const parsed = valueParser('linear-gradient(to bottom left, red, blue)');

assert.equal(getArguments(parsed.nodes[0]), [
assert.deepStrictEqual(getArguments(parsed.nodes[0]), [
[
{
type: 'word',
Expand Down Expand Up @@ -58,4 +58,3 @@ test('should get arguments', () => {
],
]);
});
test.run();
25 changes: 12 additions & 13 deletions packages/cssnano-utils/test/sameParent.test.js
@@ -1,6 +1,6 @@
'use strict';
const { test } = require('uvu');
const assert = require('uvu/assert');
const { test } = require('node:test');
const assert = require('node:assert/strict');
const postcss = require('postcss');
const sameParent = require('../src/sameParent.js');

Expand All @@ -11,7 +11,7 @@ test('should calculate same parent', () => {
const h1 = result.root.nodes[0];
const h2 = result.root.nodes[1];

assert.is(sameParent(h1, h2), true);
assert.strictEqual(sameParent(h1, h2), true);
});
});

Expand All @@ -25,7 +25,7 @@ test('should calculate same parent (detached nodes)', () => {
h1.remove();
h2.remove();

assert.is(sameParent(h1, h2), true);
assert.strictEqual(sameParent(h1, h2), true);
});
});

Expand All @@ -39,7 +39,7 @@ test('should calculate same parent (at rules)', () => {
const h1 = result.root.nodes[0].nodes[0];
const h2 = result.root.nodes[0].nodes[1];

assert.is(sameParent(h1, h2), true);
assert.strictEqual(sameParent(h1, h2), true);
});
});

Expand All @@ -53,7 +53,7 @@ test('should calculate same parent (multiple at rules)', () => {
const h1 = result.root.nodes[0].nodes[0];
const h2 = result.root.nodes[1].nodes[0];

assert.is(sameParent(h1, h2), true);
assert.strictEqual(sameParent(h1, h2), true);
});
});

Expand All @@ -67,7 +67,7 @@ test('should calculate same parent (multiple at rules (uppercase))', () => {
const h1 = result.root.nodes[0].nodes[0];
const h2 = result.root.nodes[1].nodes[0];

assert.is(sameParent(h1, h2), true);
assert.strictEqual(sameParent(h1, h2), true);
});
});

Expand All @@ -92,7 +92,7 @@ test('should calculate same parent (nested at rules)', () => {
const h1 = result.root.nodes[0].nodes[0].nodes[0];
const h2 = result.root.nodes[1].nodes[0].nodes[0];

assert.is(sameParent(h1, h2), true);
assert.strictEqual(sameParent(h1, h2), true);
});
});

Expand All @@ -117,7 +117,7 @@ test('should calculate not same parent (nested at rules)', () => {
const h1 = result.root.nodes[0].nodes[0].nodes[0];
const h2 = result.root.nodes[1].nodes[0].nodes[0];

assert.is.not(sameParent(h1, h2), true);
assert.notStrictEqual(sameParent(h1, h2), true);
});
});

Expand All @@ -142,7 +142,7 @@ test('should calculate not same parent (nested at rules) (2)', () => {
const h1 = result.root.nodes[0].nodes[0].nodes[0];
const h2 = result.root.nodes[1].nodes[0].nodes[0];

assert.is.not(sameParent(h1, h2), true);
assert.notStrictEqual(sameParent(h1, h2), true);
});
});

Expand All @@ -165,7 +165,7 @@ test('should calculate not same parent (nested at rules) (3)', () => {
const h1 = result.root.nodes[0].nodes[0];
const h2 = result.root.nodes[1].nodes[0].nodes[0];

assert.is.not(sameParent(h1, h2), true);
assert.notStrictEqual(sameParent(h1, h2), true);
});
});

Expand All @@ -188,7 +188,6 @@ test('should calculate not same parent (nested at rules) (4)', () => {
const h1 = result.root.nodes[0].nodes[0];
const h2 = result.root.nodes[1].nodes[0].nodes[0];

assert.is.not(sameParent(h1, h2), true);
assert.notStrictEqual(sameParent(h1, h2), true);
});
});
test.run();
4 changes: 2 additions & 2 deletions packages/cssnano/test/_processCss.js
@@ -1,5 +1,5 @@
'use strict';
const assert = require('uvu/assert');
const assert = require('node:assert/strict');
const postcss = require('postcss');
const cssnano = require('..');

Expand All @@ -8,7 +8,7 @@ function processCss(fixture, expected, options = { from: undefined }) {
postcss([cssnano()])
.process(fixture, options)
.then(({ css }) => {
assert.is(css, expected);
assert.strictEqual(css, expected);
});
}
module.exports = processCss;
Expand Down
9 changes: 4 additions & 5 deletions packages/cssnano/test/api.js
@@ -1,6 +1,6 @@
'use strict';
const { test } = require('uvu');
const assert = require('uvu/assert');
const { test } = require('node:test');
const assert = require('node:assert/strict');
const postcss = require('postcss');
const nano = require('..');

Expand All @@ -10,7 +10,7 @@ function pluginMacro(instance) {

return () =>
instance.process(css, { from: undefined }).then((result) => {
assert.is(result.css, min);
assert.strictEqual(result.css, min);
});
}

Expand All @@ -28,10 +28,9 @@ test('should work with sourcemaps', () => {
return postcss([nano])
.process('h1{z-index:1}', { from: undefined, map: { inline: true } })
.then(({ css }) => {
assert.is(
assert.strictEqual(
/sourceMappingURL=data:application\/json;base64/.test(css),
true
);
});
});
test.run();
9 changes: 4 additions & 5 deletions packages/cssnano/test/config_loading/config-loading.js
@@ -1,7 +1,7 @@
'use strict';
const process = require('process');
const { test } = require('uvu');
const assert = require('uvu/assert');
const { test } = require('node:test');
const assert = require('node:assert/strict');
const postcss = require('postcss');
const litePreset = require('cssnano-preset-lite');
const defaultPreset = require('cssnano-preset-default');
Expand All @@ -23,11 +23,10 @@ test.after(() => {

test('should read the cssnano configuration file', () => {
const processor = postcss([cssnano]);
assert.is(processor.plugins.length, litePreset().plugins.length);
assert.strictEqual(processor.plugins.length, litePreset().plugins.length);
});

test('PostCSS config should override the cssnano config', () => {
const processor = postcss([cssnano({ preset: 'default' })]);
assert.is(processor.plugins.length, defaultPreset().plugins.length);
assert.strictEqual(processor.plugins.length, defaultPreset().plugins.length);
});
test.run();
3 changes: 1 addition & 2 deletions packages/cssnano/test/fixtures.js
@@ -1,5 +1,5 @@
'use strict';
const { test } = require('uvu');
const { test } = require('node:test');
const processCss = require('./_processCss');

test(
Expand Down Expand Up @@ -358,4 +358,3 @@ test(
'should remove leading zeroes from reduced calc values',
processCss(`.box { margin: calc(-.5 * 1rem); }`, `.box{margin:-.5rem}`)
);
test.run();
7 changes: 3 additions & 4 deletions packages/cssnano/test/issue26.js
@@ -1,6 +1,6 @@
'use strict';
const { test } = require('uvu');
const assert = require('uvu/assert');
const { test } = require('node:test');
const assert = require('node:assert/strict');
const postcss = require('postcss');
const nano = require('..');

Expand Down Expand Up @@ -44,6 +44,5 @@ test('it should compress whitespace after node.clone()', () => {

return processor
.process(fixture, { from: undefined })
.then((r) => assert.is(r.css, expected));
.then((r) => assert.strictEqual(r.css, expected));
});
test.run();
7 changes: 3 additions & 4 deletions packages/cssnano/test/issue315.js
@@ -1,6 +1,6 @@
'use strict';
const { test } = require('uvu');
const assert = require('uvu/assert');
const { test } = require('node:test');
const assert = require('node:assert/strict');
const postcss = require('postcss');
const fontMagician = require('postcss-font-magician');
const cssnano = require('..');
Expand All @@ -14,10 +14,9 @@ test('should work with postcss-font-magician', () => {
return postcss([fontMagician({}), cssnano()])
.process(css, { from: undefined })
.then((result) => {
assert.snapshot(
assert.strictEqual(
result.css,
`@font-face{font-family:Alice;font-style:normal;font-weight:400;src:url(//fonts.gstatic.com/s/alice/v20/OpNCnoEEmtHa6GcArgo.eot?#) format("eot"),url(//fonts.gstatic.com/s/alice/v20/OpNCnoEEmtHa6GcOrg4.woff2) format("woff2"),url(//fonts.gstatic.com/s/alice/v20/OpNCnoEEmtHa6GcArgg.woff) format("woff")}body{font-family:Alice}`
);
});
});
test.run();
7 changes: 3 additions & 4 deletions packages/cssnano/test/issue420.js
@@ -1,6 +1,6 @@
'use strict';
const { test } = require('uvu');
const assert = require('uvu/assert');
const { test } = require('node:test');
const assert = require('node:assert/strict');
const postcss = require('postcss');
const fontMagician = require('postcss-font-magician');
const cssnano = require('..');
Expand All @@ -15,10 +15,9 @@ test('should work with postcss-font-magician with `display` parameter', () => {
return postcss([fontMagician({ display: 'optional' }), cssnano()])
.process(css, { from: undefined })
.then((result) => {
assert.snapshot(
assert.strictEqual(
result.css,
`@font-face{font-display:optional;font-family:Alice;font-style:normal;font-weight:400;src:url(//fonts.gstatic.com/s/alice/v20/OpNCnoEEmtHa6GcArgo.eot?#) format("eot"),url(//fonts.gstatic.com/s/alice/v20/OpNCnoEEmtHa6GcOrg4.woff2) format("woff2"),url(//fonts.gstatic.com/s/alice/v20/OpNCnoEEmtHa6GcArgg.woff) format("woff")}body{font-family:Alice}`
);
});
});
test.run();
7 changes: 3 additions & 4 deletions packages/cssnano/test/issue579.js
@@ -1,6 +1,6 @@
'use strict';
const { test } = require('uvu');
const assert = require('uvu/assert');
const { test } = require('node:test');
const assert = require('node:assert/strict');
const postcss = require('postcss');
const cssnano = require('..');

Expand All @@ -16,10 +16,9 @@ test('should support `env()` and `constant()` is an iPhone X-only feature', () =
return postcss([cssnano])
.process(css, { from: undefined })
.then((result) => {
assert.is(
assert.strictEqual(
result.css,
'@supports (height:env(safe-area-inset-bottom)){.footer{padding-bottom:calc(env(safe-area-inset-bottom)*3)!important}}'
);
});
});
test.run();

0 comments on commit 78c6be5

Please sign in to comment.