Skip to content

Commit

Permalink
Move to node test runner
Browse files Browse the repository at this point in the history
  • Loading branch information
ai committed Oct 4, 2024
1 parent b04c037 commit a7177b9
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 74 deletions.
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"license": "MIT",
"repository": "postcss/postcss-safe-parser",
"scripts": {
"unit": "uvu . '\\.test\\.js$'",
"unit": "node --test test/parse.test.js",
"test:unit": "pnpm unit",
"test:lint": "eslint .",
"test:integration": "node test/integration.js",
Expand Down Expand Up @@ -52,8 +52,7 @@
"eslint-plugin-prefer-let": "^3.0.1",
"eslint-plugin-promise": "^6.1.1",
"postcss": "^8.4.31",
"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.

59 changes: 35 additions & 24 deletions test/parse.test.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
let { eachTest, jsonify } = require('postcss-parser-tests')
let { equal, not } = require('uvu/assert')
let { test } = require('uvu')
let { deepStrictEqual, equal } = require('node:assert')
let { test } = require('node:test')

let parse = require('../lib/safe-parse')

eachTest((name, css, json) => {
if (name !== 'apply.css' && name !== 'custom-properties.css') {
test('parses ' + name, () => {
let parsed = jsonify(parse(css, { from: name }))
equal(parsed, json)
deepStrictEqual(parsed, json)
})
}
})
Expand Down Expand Up @@ -73,9 +73,7 @@ test('fixes property without semicolon in safe mode', () => {
})

test('does not fall on missed semicolon in IE filter', () => {
not.throws(() => {
parse("a { one: two: progid:DX(a='1', b='2'); }")
})
parse("a { one: two: progid:DX(a='1', b='2'); }")
})

test('fixes double colon in safe mode', () => {
Expand All @@ -89,37 +87,50 @@ test('fixes colon instead of semicolon', () => {
})

test('fixes {} error', () => {
let root = parse(`:root { --example-var: { "Version": { "Build": "10.30.7.350828.20230224122352", "Source": "10.30.7.350828.1", "Required": "10.30.7.307232"; }}}; @font-face { font-family: 'Calibri'; }`)
equal(root.toString(), `:root { --example-var: { "Version": { "Build": "10.30.7.350828.20230224122352", "Source": "10.30.7.350828.1", "Required": "10.30.7.307232"; }}}; @font-face { font-family: 'Calibri'; }`)
let root = parse(
`:root { --example-var: { "Version": { "Build": "10.30.7.350828.20230224122352", "Source": "10.30.7.350828.1", "Required": "10.30.7.307232"; }}}; @font-face { font-family: 'Calibri'; }`
)
equal(
root.toString(),
`:root { --example-var: { "Version": { "Build": "10.30.7.350828.20230224122352", "Source": "10.30.7.350828.1", "Required": "10.30.7.307232"; }}}; @font-face { font-family: 'Calibri'; }`
)
})

test('Rule at the start of tokens', () => {
let root = parse(`.start { font-size: 16px; }`);
equal(root.toString(), `.start { font-size: 16px; }`);
});
let root = parse(`.start { font-size: 16px; }`)
equal(root.toString(), `.start { font-size: 16px; }`)
})

test('Complex nested structures with JSON-like properties', () => {
let root = parse(`:root { --complex: {"nested": {"key": "value"}, "array": [1, {"sub": "value"}]}; } @font-face { font-family: 'Calibri'; }`);
equal(root.toString(), `:root { --complex: {"nested": {"key": "value"}, "array": [1, {"sub": "value"}]}; } @font-face { font-family: 'Calibri'; }`);
});
let root = parse(
`:root { --complex: {"nested": {"key": "value"}, "array": [1, {"sub": "value"}]}; } @font-face { font-family: 'Calibri'; }`
)
equal(
root.toString(),
`:root { --complex: {"nested": {"key": "value"}, "array": [1, {"sub": "value"}]}; } @font-face { font-family: 'Calibri'; }`
)
})

test('Multiple rules with one JSON-like custom property', () => {
let root = parse(`
.class1 { margin: 10px; }
:root { --jsonProp: {"a": 1, "b": {"c": 3}}; }
.class2 { padding: 20px; }
`);
equal(root.toString(), `
`)
equal(
root.toString(),
`
.class1 { margin: 10px; }
:root { --jsonProp: {"a": 1, "b": {"c": 3}}; }
.class2 { padding: 20px; }
`);
});
`
)
})

test('Custom property at start without modifications', () => {
let root = parse(`--example: {"key": "value"}; .class { color: black; }`);
equal(root.toString(), `--example: {"key": "value"}; .class { color: black; }`);
});

test.run()

let root = parse(`--example: {"key": "value"}; .class { color: black; }`)
equal(
root.toString(),
`--example: {"key": "value"}; .class { color: black; }`
)
})

0 comments on commit a7177b9

Please sign in to comment.