-
-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathsettings-and-plugins.js
159 lines (141 loc) · 4.18 KB
/
settings-and-plugins.js
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
import assert from 'node:assert/strict'
import test from 'node:test'
import {promisify} from 'node:util'
import {engine} from 'unified-engine'
import {noop} from './util/noop-processor.js'
import {spy} from './util/spy.js'
const run = promisify(engine)
const fixtures = new URL('fixtures/', import.meta.url)
test('settings', async function (t) {
await t.test('should use `settings`', async function () {
const stderr = spy()
let called = false
const code = await run({
cwd: new URL('one-file/', fixtures),
extensions: ['txt'],
files: ['.'],
processor: noop().use(function () {
assert.deepEqual(
this.data('settings'),
{alpha: true},
'should configure'
)
called = true
}),
settings: {alpha: true},
streamError: stderr.stream
})
assert.equal(code, 0)
assert.equal(stderr(), 'one.txt: no issues found\n')
assert.equal(called, true)
})
await t.test('should cascade `settings`', async function () {
const stderr = spy()
let called = false
const code = await run({
cwd: new URL('config-settings-cascade/', fixtures),
extensions: ['txt'],
files: ['.'],
processor: noop().use(function () {
assert.deepEqual(
this.data('settings'),
{alpha: false, bravo: 'charlie', delta: 1},
'should configure'
)
called = true
}),
rcName: '.foorc',
settings: {alpha: false, bravo: 'charlie'},
streamError: stderr.stream
})
assert.equal(code, 0)
assert.equal(stderr(), 'one.txt: no issues found\n')
assert.equal(called, true)
})
})
test('plugins', async function (t) {
await t.test('should use `plugins` as list of functions', async function () {
const stderr = spy()
let calls = 0
const code = await run({
cwd: new URL('one-file/', fixtures),
extensions: ['txt'],
files: ['.'],
plugins: [
function () {
return function () {
calls++
}
},
[
/**
* @param {unknown} options
* Configuration.
* @returns
* Transform.
*/
function (options) {
return function () {
assert.deepEqual(options, {alpha: true}, 'transformer')
calls++
}
},
{alpha: true}
]
],
processor: noop,
streamError: stderr.stream
})
assert.equal(code, 0)
assert.equal(stderr(), 'one.txt: no issues found\n')
assert.equal(calls, 2)
})
await t.test('should use `plugins` as list of strings', async function () {
const stderr = spy()
globalThis.unifiedEngineTestCalls = 0
globalThis.unifiedEngineTestValues = {}
const code = await run({
cwd: new URL('config-plugins-basic-reconfigure/', fixtures),
extensions: ['txt'],
files: ['.'],
plugins: [
'./preset/index.js',
['./preset/plugin.js', {two: false, three: true}]
],
processor: noop(),
streamError: stderr.stream
})
assert.equal(code, 0)
assert.equal(stderr(), 'one.txt: no issues found\n')
assert.equal(globalThis.unifiedEngineTestCalls, 1)
assert.deepEqual(
globalThis.unifiedEngineTestValues,
{one: true, three: true, two: false},
'should pass the correct options to plugins'
)
})
await t.test('should use `plugins` as list of objects', async function () {
const stderr = spy()
globalThis.unifiedEngineTestCalls = 0
globalThis.unifiedEngineTestValues = {}
const code = await run({
cwd: new URL('config-plugins-basic-reconfigure/', fixtures),
extensions: ['txt'],
files: ['.'],
plugins: {
'./preset/index.js': null,
'./preset/plugin.js': {three: true, two: false}
},
processor: noop(),
streamError: stderr.stream
})
assert.equal(code, 0)
assert.equal(stderr(), 'one.txt: no issues found\n')
assert.equal(globalThis.unifiedEngineTestCalls, 1)
assert.deepEqual(
globalThis.unifiedEngineTestValues,
{one: true, three: true, two: false},
'should pass the correct options to plugins'
)
})
})