-
Notifications
You must be signed in to change notification settings - Fork 58
Expand file tree
/
Copy pathsetup.js
More file actions
64 lines (53 loc) · 1.79 KB
/
Copy pathsetup.js
File metadata and controls
64 lines (53 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
const { describe, it, before, after } = require('node:test');
const assert = require('node:assert');
const postcss = require('postcss');
const url = require('../src');
const fs = require('fs');
// expose node:test runner functions as globals (mocha-like API)
global.describe = describe;
global.it = it;
global.before = before;
global.after = after;
// expose a chai-like assert: callable like `assert(value)` (node:assert is a
// function aliasing `assert.ok`), with all node:assert methods + a `notOk` helper
function assertFn(...args) {
return assert(...args);
}
Object.assign(assertFn, assert, {
notOk(value, message) {
assert.ok(!value, message);
}
});
global.assert = assertFn;
global.compareFixtures = compareFixtures;
global.read = read;
global.processedCss = processedCss;
global.postcss = postcss;
global.postcssUrl = url;
function compareFixtures(name, msg, opts, postcssOpts, plugin) {
it(msg, () => {
opts = opts || {};
const plugins = [];
if (plugin) {
plugins.push(plugin());
}
plugins.push(url(opts));
return postcss(plugins).process(read(`fixtures/${name}`), postcssOpts)
.then((result) => {
const actual = result.css;
const expected = read(`fixtures/${name}.expected`);
// handy thing: checkout actual in the *.actual.css file
fs.writeFile(`test/fixtures/${name}.actual.css`, actual, () => {});
assert.equal(actual, expected);
});
});
}
function read(name) {
return fs.readFileSync(`test/${name}.css`, 'utf8').trim();
}
function processedCss(fixtures, urlOpts, postcssOpts) {
return postcss()
.use(url(urlOpts))
.process(read(fixtures), postcssOpts)
.then((res) => res.css);
}