From a978e9d7417a5d0db894f331b154da22d7132c92 Mon Sep 17 00:00:00 2001 From: Andrey Sitnik Date: Tue, 12 Nov 2024 15:40:39 +0100 Subject: [PATCH] Move tests to Node.js built-in test runner --- package.json | 5 ++--- pnpm-lock.yaml | 47 ----------------------------------------- test/liner.test.js | 10 ++++----- test/parse.test.js | 28 ++++++++++++------------ test/preprocess.test.js | 14 ++++++------ test/stringify.test.js | 6 ++---- test/sugarss.test.js | 6 ++---- test/tokenize.test.js | 6 +++--- 8 files changed, 32 insertions(+), 90 deletions(-) diff --git a/package.json b/package.json index feb0391..e25c139 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,7 @@ "license": "MIT", "repository": "postcss/sugarss", "scripts": { - "unit": "uvu . '\\.test\\.js$'", + "unit": "node --test test/*.test.js", "test:coverage": "c8 pnpm unit", "test:lint": "eslint .", "test": "pnpm run /^test:/" @@ -51,8 +51,7 @@ "clean-publish": "^5.1.0", "eslint": "^9.14.0", "postcss": "^8.4.49", - "postcss-parser-tests": "^8.8.0", - "uvu": "^0.5.6" + "postcss-parser-tests": "^8.8.0" }, "prettier": { "arrowParens": "avoid", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 87e2ffc..8870be7 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -26,9 +26,6 @@ importers: postcss-parser-tests: specifier: ^8.8.0 version: 8.8.0 - uvu: - specifier: ^0.5.6 - version: 0.5.6 packages: @@ -369,14 +366,6 @@ packages: resolution: {integrity: sha512-8QmQKqEASLd5nx0U1B1okLElbUuuttJ/AnYmRXbbbGDWh6uS208EjD4Xqq/I9wK7u0v6O08XhTWnt5XtEbR6Dg==} engines: {node: '>= 0.4'} - dequal@2.0.3: - resolution: {integrity: sha512-0je+qPKHEMohvfRTCEo3CrPG6cAzAYgmzKyxRiYSSDkS6eGJdyVJm7WaYA5ECaAD9wLB2T4EEeymA5aFVcYXCA==} - engines: {node: '>=6'} - - diff@5.2.0: - resolution: {integrity: sha512-uIFDxqpRZGZ6ThOk84hEfqWoHx2devRFvpTZcTHur85vImfaxUbTW9Ryh4CpCuDnToOP1CEtXKIgytHBPVff5A==} - engines: {node: '>=0.3.1'} - doctrine@2.1.0: resolution: {integrity: sha512-35mSku4ZXK0vfCuHEDAwt55dg2jNajHZ1odvF+8SSr82EsZY4QmXfuWso8oEd8zRhVObSN18aM0CjSdoBX7zIw==} engines: {node: '>=0.10.0'} @@ -821,10 +810,6 @@ packages: keyv@4.5.4: resolution: {integrity: sha512-oxVHkHR/EJf2CNXnWxRLW6mg7JyCCUcG0DtEGmL2ctUo1PNTin1PUil+r/+4r5MpVgC/fn1kjsx7mjSujKqIpw==} - kleur@4.1.5: - resolution: {integrity: sha512-o+NO+8WrRiQEE4/7nwRJhN1HWpVmJm511pBHUxPLtp0BUISzlBplORYSmTclCnJvQq2tKu/sgl3xVpkc7ZWuQQ==} - engines: {node: '>=6'} - levn@0.4.1: resolution: {integrity: sha512-+bT2uH4E5LGE7h/n3evcS/sQlJXCpIp6ym8OWJ5eV6+67Dsql/LaaT7qJBAt2rzfoa/5QBGBhxDix1dMt2kQKQ==} engines: {node: '>= 0.8.0'} @@ -869,10 +854,6 @@ packages: resolution: {integrity: sha512-qOOzS1cBTWYF4BH8fVePDBOO9iptMnGUEZwNc/cMWnTV2nVLZ7VoNWEPHkYczZA0pdoA7dl6e7FL659nX9S2aw==} engines: {node: '>=16 || 14 >=14.17'} - mri@1.2.0: - resolution: {integrity: sha512-tzzskb3bG8LvYGFF/mDTpq3jpI6Q9wc3LEmBaghu+DdCssd1FakN7Bc0hVNmEyGq1bq3RgfkCb3cmQLpNPOroA==} - engines: {node: '>=4'} - ms@2.1.3: resolution: {integrity: sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==} @@ -1004,10 +985,6 @@ packages: run-parallel@1.2.0: resolution: {integrity: sha512-5l4VyZR86LZ/lDxZTR6jqL8AFE2S0IFLMP26AbjsLVADxHdhB/c0GUsH+y39UfCi3dzz8OlQuPmnaJOMoDHQBA==} - sade@1.8.1: - resolution: {integrity: sha512-xal3CZX1Xlo/k4ApwCFrHVACi9fBqJ7V+mwhBsuf/1IOKbBy098Fex+Wa/5QMubw09pSZ/u8EY8PWgevJsXp1A==} - engines: {node: '>=6'} - safe-array-concat@1.1.2: resolution: {integrity: sha512-vj6RsCsWBCf19jIeHEfkRMw8DPiBb+DMXklQ/1SGDHOMlHdPUkZXFQ2YdplS23zESTijAcurb1aSgJA3AgMu1Q==} engines: {node: '>=0.4'} @@ -1160,11 +1137,6 @@ packages: uri-js@4.4.1: resolution: {integrity: sha512-7rKUyy33Q1yc98pQ1DAmLtwX109F7TIfWlW1Ydo8Wl1ii1SeHieeh0HHfPeL2fMXK6z0s8ecKs9frCuLJvndBg==} - uvu@0.5.6: - resolution: {integrity: sha512-+g8ENReyr8YsOc6fv/NVJs2vFdHBnBNdfE49rshrTzDWOlUx4Gq7KOS2GD8eqhy2j+Ejq29+SbKH8yjkAqXqoA==} - engines: {node: '>=8'} - hasBin: true - v8-to-istanbul@9.3.0: resolution: {integrity: sha512-kiGUalWN+rgBJ/1OHZsBtU4rXZOfj/7rKQxULKlIzwzQSvMJUUNgPwJEEh7gU6xEVxC0ahoOBvN2YI8GH6FNgA==} engines: {node: '>=10.12.0'} @@ -1602,10 +1574,6 @@ snapshots: has-property-descriptors: 1.0.2 object-keys: 1.1.1 - dequal@2.0.3: {} - - diff@5.2.0: {} - doctrine@2.1.0: dependencies: esutils: 2.0.3 @@ -2123,8 +2091,6 @@ snapshots: dependencies: json-buffer: 3.0.1 - kleur@4.1.5: {} - levn@0.4.1: dependencies: prelude-ls: 1.2.1 @@ -2163,8 +2129,6 @@ snapshots: minipass@7.1.2: {} - mri@1.2.0: {} - ms@2.1.3: {} nanoid@3.3.7: {} @@ -2286,10 +2250,6 @@ snapshots: dependencies: queue-microtask: 1.2.3 - sade@1.8.1: - dependencies: - mri: 1.2.0 - safe-array-concat@1.1.2: dependencies: call-bind: 1.0.7 @@ -2474,13 +2434,6 @@ snapshots: dependencies: punycode: 2.3.1 - uvu@0.5.6: - dependencies: - dequal: 2.0.3 - diff: 5.2.0 - kleur: 4.1.5 - sade: 1.8.1 - v8-to-istanbul@9.3.0: dependencies: '@jridgewell/trace-mapping': 0.3.25 diff --git a/test/liner.test.js b/test/liner.test.js index 993615a..054b737 100644 --- a/test/liner.test.js +++ b/test/liner.test.js @@ -1,5 +1,5 @@ -let { test } = require('uvu') -let { equal } = require('uvu/assert') +let { deepStrictEqual } = require('node:assert') +let { test } = require('node:test') let liner = require('../liner') @@ -9,7 +9,7 @@ test('packs tokens by lines', () => { ['newline', '\n'], ['word', 'b'] ] - equal(liner(tokens), [ + deepStrictEqual(liner(tokens), [ [ ['word', 'a'], ['newline', '\n'] @@ -24,7 +24,7 @@ test('ignores newline inside brackets', () => { ['newline', '\n'], [')', ')'] ] - equal(liner(tokens), [ + deepStrictEqual(liner(tokens), [ [ ['(', '('], ['newline', '\n'], @@ -32,5 +32,3 @@ test('ignores newline inside brackets', () => { ] ]) }) - -test.run() diff --git a/test/parse.test.js b/test/parse.test.js index 0d8e3b5..9e742a7 100644 --- a/test/parse.test.js +++ b/test/parse.test.js @@ -1,8 +1,8 @@ +let { deepStrictEqual, equal, throws } = require('node:assert') let { readdirSync, readFileSync } = require('node:fs') let { extname, join } = require('node:path') +let { test } = require('node:test') let { jsonify } = require('postcss-parser-tests') -let { test } = require('uvu') -let { equal, throws } = require('uvu/assert') let parse = require('../parse') @@ -14,55 +14,55 @@ test('detects indent', () => { test('throws on first indent', () => { throws(() => { parse(' @charset "UTF-8"') - }, ':1:1: First line should not have indent') + }, /:1:1: First line should not have indent/) }) test('throws on too big indent', () => { throws(() => { parse('@supports\n @media\n // test') - }, ':3:1: Expected 4 indent, but get 6') + }, /:3:1: Expected 4 indent, but get 6/) }) test('throws on wrong indent step', () => { throws(() => { parse('@supports\n @media\n @media') - }, ':3:1: Expected 0 or 2 indent, but get 1') + }, /:3:1: Expected 0 or 2 indent, but get 1/) }) test('throws on decl without property', () => { throws(() => { parse(': black') - }, ':1:1: Declaration without name') + }, /:1:1: Declaration without name/) }) test('throws on space between property', () => { throws(() => { parse('one two: black') - }, ':1:5: Unexpected separator in property') + }, /:1:5: Unexpected separator in property/) }) test('throws on semicolon in declaration', () => { throws(() => { parse('a\n color: black;') - }, ':2:15: Unnecessary semicolon') + }, /:2:15: Unnecessary semicolon/) }) test('throws on semicolon in at-rule', () => { throws(() => { parse('@charset "UTF-8";') - }, ':1:17: Unnecessary semicolon') + }, /:1:17: Unnecessary semicolon/) }) test('throws on curly in rule', () => { throws(() => { parse('a {\n color: black') - }, ':1:3: Unnecessary curly bracket') + }, /:1:3: Unnecessary curly bracket/) }) test('throws on curly in at-rule', () => { throws(() => { parse('@media (screen) {\n color: black') - }, ':1:17: Unnecessary curly bracket') + }, /:1:17: Unnecessary curly bracket/) }) test('keeps trailing spaces', () => { @@ -90,7 +90,7 @@ test('generates correct source maps on trailing spaces', () => { }) test('sets end position for root', () => { - equal(parse('a\n b: 1\n').source.end, { column: 6, line: 2 }) + deepStrictEqual(parse('a\n b: 1\n').source.end, { column: 6, line: 2 }) }) let tests = readdirSync(join(__dirname, 'cases')).filter( @@ -114,8 +114,6 @@ for (let name of tests) { } }) equal(result.css, css) - equal(jsonify(root), JSON.parse(json.trim())) + deepStrictEqual(jsonify(root), JSON.parse(json.trim())) }) } - -test.run() diff --git a/test/preprocess.test.js b/test/preprocess.test.js index 6629883..68f7612 100644 --- a/test/preprocess.test.js +++ b/test/preprocess.test.js @@ -1,11 +1,11 @@ +let { deepStrictEqual, throws } = require('node:assert') +let { test } = require('node:test') let { Input } = require('postcss') -let { test } = require('uvu') -let { equal, throws } = require('uvu/assert') let preprocess = require('../preprocess') function run(lines, result) { - equal(preprocess(new Input(''), lines), result) + deepStrictEqual(preprocess(new Input(''), lines), result) } let defaults = { @@ -385,7 +385,7 @@ test('detects mixed tabs and spaces in indent', () => { ['word', 'ab'] ] ]) - }, ':1:2: Mixed tabs and spaces are not allowed') + }, /:1:2: Mixed tabs and spaces are not allowed/) }) test('detects mixed tabs and spaces in indents', () => { @@ -400,7 +400,7 @@ test('detects mixed tabs and spaces in indents', () => { ['word', 'ab'] ] ]) - }, ':2:1: Mixed tabs and spaces are not allowed') + }, /:2:1: Mixed tabs and spaces are not allowed/) }) test('shows correct error position', () => { @@ -421,7 +421,5 @@ test('shows correct error position', () => { ['newline', '\n', 4] ] ]) - }, ':4:2: Mixed tabs and spaces are not allowed') + }, /:4:2: Mixed tabs and spaces are not allowed/) }) - -test.run() diff --git a/test/stringify.test.js b/test/stringify.test.js index 7177ae9..72455f8 100644 --- a/test/stringify.test.js +++ b/test/stringify.test.js @@ -1,7 +1,7 @@ +let { equal } = require('node:assert') let { readdirSync, readFileSync } = require('node:fs') let { extname, join } = require('node:path') -let { test } = require('uvu') -let { equal } = require('uvu/assert') +let { test } = require('node:test') let parse = require('../parse') let stringify = require('../stringify') @@ -32,5 +32,3 @@ for (let name of tests) { run(read(name)) }) } - -test.run() diff --git a/test/sugarss.test.js b/test/sugarss.test.js index 17984a2..61e862e 100644 --- a/test/sugarss.test.js +++ b/test/sugarss.test.js @@ -1,5 +1,5 @@ -let { test } = require('uvu') -let { equal } = require('uvu/assert') +let { equal } = require('node:assert') +let { test } = require('node:test') let sugarss = require('../') @@ -10,5 +10,3 @@ test('has parse()', () => { test('has stringify()', () => { equal(typeof sugarss.stringify, 'function') }) - -test.run() diff --git a/test/tokenize.test.js b/test/tokenize.test.js index 90ef8c2..18dcebd 100644 --- a/test/tokenize.test.js +++ b/test/tokenize.test.js @@ -1,11 +1,11 @@ +let { deepStrictEqual } = require('node:assert') +let { test } = require('node:test') let { Input } = require('postcss') -let { test } = require('uvu') -let { equal } = require('uvu/assert') let tokenize = require('../tokenize') function run(css, tokens) { - equal(tokenize(new Input(css)), tokens) + deepStrictEqual(tokenize(new Input(css)), tokens) } test('tokenizes inine comments', () => {