-
-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathconfiguration-transform.js
75 lines (65 loc) · 2.17 KB
/
configuration-transform.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
/**
* @import {Preset} from 'unified-engine'
* @import {Configuration} from '../lib/configuration.js'
*/
/**
* @typedef RawValue
* Format of our example custom config.
* @property {Preset['settings']} options
* Settings.
* @property {Preset['plugins']} plugs
* Plugins.
*/
import assert from 'node:assert/strict'
import test from 'node:test'
import {engine} from 'unified-engine'
import {noop} from './util/noop-processor.js'
import {spy} from './util/spy.js'
const fixtures = new URL('fixtures/', import.meta.url)
test('`configTransform`', async function (t) {
await t.test('should support a `configTransform`', async function () {
await new Promise(function (resolve) {
const stderr = spy()
globalThis.unifiedEngineTestCalls = 0
globalThis.unifiedEngineTestValues = {}
engine(
{
/**
* @param {RawValue} raw
* Format of our example custom config.
* @returns
* Expected format.
*/
configTransform(raw) {
return {settings: raw.options, plugins: raw.plugs}
},
cwd: new URL('config-transform/', fixtures),
extensions: ['txt'],
files: ['.'],
packageField: 'foo',
processor: noop(),
streamError: stderr.stream
},
function (error, code, result) {
assert.equal(error, undefined)
assert.equal(code, 0)
assert.equal(stderr(), 'one.txt: no issues found\n')
/** @type {Configuration} */
// @ts-expect-error: access the internals
const config = result.configuration
const cache = config.findUp.cache
const keys = Object.keys(cache)
assert.equal(keys.length, 1)
const value = cache[keys[0]]
assert(typeof value === 'object')
assert('settings' in value)
assert.deepEqual(value.settings, {foxtrot: true})
assert.deepEqual(value.plugins[0][1], {golf: false})
assert.equal(globalThis.unifiedEngineTestCalls, 1)
assert.deepEqual(globalThis.unifiedEngineTestValues, {golf: false})
resolve(undefined)
}
)
})
})
})