Skip to content

Commit

Permalink
Move tests to Node.js built-in test runner
Browse files Browse the repository at this point in the history
  • Loading branch information
ai committed Nov 12, 2024
1 parent 4079884 commit a978e9d
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 90 deletions.
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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:/"
Expand Down Expand Up @@ -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",
Expand Down
47 changes: 0 additions & 47 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 4 additions & 6 deletions test/liner.test.js
Original file line number Diff line number Diff line change
@@ -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')

Expand All @@ -9,7 +9,7 @@ test('packs tokens by lines', () => {
['newline', '\n'],
['word', 'b']
]
equal(liner(tokens), [
deepStrictEqual(liner(tokens), [
[
['word', 'a'],
['newline', '\n']
Expand All @@ -24,13 +24,11 @@ test('ignores newline inside brackets', () => {
['newline', '\n'],
[')', ')']
]
equal(liner(tokens), [
deepStrictEqual(liner(tokens), [
[
['(', '('],
['newline', '\n'],
[')', ')']
]
])
})

test.run()
28 changes: 13 additions & 15 deletions test/parse.test.js
Original file line number Diff line number Diff line change
@@ -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')

Expand All @@ -14,55 +14,55 @@ test('detects indent', () => {
test('throws on first indent', () => {
throws(() => {
parse(' @charset "UTF-8"')
}, '<css input>:1:1: First line should not have indent')
}, /<css input>:1:1: First line should not have indent/)
})

test('throws on too big indent', () => {
throws(() => {
parse('@supports\n @media\n // test')
}, '<css input>:3:1: Expected 4 indent, but get 6')
}, /<css input>:3:1: Expected 4 indent, but get 6/)
})

test('throws on wrong indent step', () => {
throws(() => {
parse('@supports\n @media\n @media')
}, '<css input>:3:1: Expected 0 or 2 indent, but get 1')
}, /<css input>:3:1: Expected 0 or 2 indent, but get 1/)
})

test('throws on decl without property', () => {
throws(() => {
parse(': black')
}, '<css input>:1:1: Declaration without name')
}, /<css input>:1:1: Declaration without name/)
})

test('throws on space between property', () => {
throws(() => {
parse('one two: black')
}, '<css input>:1:5: Unexpected separator in property')
}, /<css input>:1:5: Unexpected separator in property/)
})

test('throws on semicolon in declaration', () => {
throws(() => {
parse('a\n color: black;')
}, '<css input>:2:15: Unnecessary semicolon')
}, /<css input>:2:15: Unnecessary semicolon/)
})

test('throws on semicolon in at-rule', () => {
throws(() => {
parse('@charset "UTF-8";')
}, '<css input>:1:17: Unnecessary semicolon')
}, /<css input>:1:17: Unnecessary semicolon/)
})

test('throws on curly in rule', () => {
throws(() => {
parse('a {\n color: black')
}, '<css input>:1:3: Unnecessary curly bracket')
}, /<css input>:1:3: Unnecessary curly bracket/)
})

test('throws on curly in at-rule', () => {
throws(() => {
parse('@media (screen) {\n color: black')
}, '<css input>:1:17: Unnecessary curly bracket')
}, /<css input>:1:17: Unnecessary curly bracket/)
})

test('keeps trailing spaces', () => {
Expand Down Expand Up @@ -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(
Expand All @@ -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()
14 changes: 6 additions & 8 deletions test/preprocess.test.js
Original file line number Diff line number Diff line change
@@ -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 = {
Expand Down Expand Up @@ -385,7 +385,7 @@ test('detects mixed tabs and spaces in indent', () => {
['word', 'ab']
]
])
}, '<css input>:1:2: Mixed tabs and spaces are not allowed')
}, /<css input>:1:2: Mixed tabs and spaces are not allowed/)
})

test('detects mixed tabs and spaces in indents', () => {
Expand All @@ -400,7 +400,7 @@ test('detects mixed tabs and spaces in indents', () => {
['word', 'ab']
]
])
}, '<css input>:2:1: Mixed tabs and spaces are not allowed')
}, /<css input>:2:1: Mixed tabs and spaces are not allowed/)
})

test('shows correct error position', () => {
Expand All @@ -421,7 +421,5 @@ test('shows correct error position', () => {
['newline', '\n', 4]
]
])
}, '<css input>:4:2: Mixed tabs and spaces are not allowed')
}, /<css input>:4:2: Mixed tabs and spaces are not allowed/)
})

test.run()
6 changes: 2 additions & 4 deletions test/stringify.test.js
Original file line number Diff line number Diff line change
@@ -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')
Expand Down Expand Up @@ -32,5 +32,3 @@ for (let name of tests) {
run(read(name))
})
}

test.run()
6 changes: 2 additions & 4 deletions test/sugarss.test.js
Original file line number Diff line number Diff line change
@@ -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('../')

Expand All @@ -10,5 +10,3 @@ test('has parse()', () => {
test('has stringify()', () => {
equal(typeof sugarss.stringify, 'function')
})

test.run()
6 changes: 3 additions & 3 deletions test/tokenize.test.js
Original file line number Diff line number Diff line change
@@ -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', () => {
Expand Down

0 comments on commit a978e9d

Please sign in to comment.