/
rollup.test.config.js
69 lines (64 loc) · 2.73 KB
/
rollup.test.config.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
import createTestPackageJson from 'rollup-plugin-create-test-package-json'
import multiInputPkg from 'rollup-plugin-multi-input'
import relativeToPackage from 'rollup-plugin-relative-to-package'
import createPackFile from '@toolbuilder/rollup-plugin-create-pack-file'
import runCommands, { shellCommand } from '@toolbuilder/rollup-plugin-commands'
import { tmpdir } from 'os'
import { join } from 'path'
// multiInput is CJS module transpiled from TypeScript. Default is not coming in properly.
const isFunction = object => object && typeof (object) === 'function'
const multiInput = isFunction(multiInputPkg) ? multiInputPkg : multiInputPkg.default
/*
This Rollup configuration is used by the 'check:packfile' script to validate that the
packfile can pass the unit tests. It assumes 'pnpm' is installed. You can use 'npm' by
changing 'pnpm' to 'npm' in this configuration.
Use this configuration by running 'pnpm run check:packfile'. It will create a temporary
directory, build a node package in the directory, and run the unit tests on the packfile.
*/
// This is where the test package is created
const testPackageDir = join(tmpdir(), `${Date.now()}`)
export default [
{
// process all unit tests, and specify output in 'test' directory of testPackageDir
input: ['test/**/*test.js'],
output: {
format: 'es',
dir: testPackageDir,
preserveModules: true // Generate one unit test for each input unit test
},
plugins: [
multiInput(), // Handles the input glob above
// Oddly enough, relativeToPackage isn't required to process the unit tests
// because they use self-referencing import statements. It does tell Rollup
// which files are external though.
relativeToPackage(),
createTestPackageJson({ // Creates package.json for testPackageDir
// Provide information that plugin can't pick up for itself
testPackageJson: {
scripts: {
test: 'tape -r esm test/**/*test.js | tap-nirvana'
},
// dependencies are populated automatically
devDependencies: {
// These are the dependencies for the test runner
esm: '^3.2.25',
tape: '^5.0.1',
'tap-nirvana': '^1.1.0'
}
}
}),
createPackFile({ // and move it to output.dir (i.e. testPackageDir)
packCommand: 'pnpm pack'
}),
runCommands({
commands: [
// Install dependencies and run the unit test
// The -C parameter ensures that the test does not resolve
// any packages outside testPackageDir. Ordinarily, it
// would pickup packages in this package too.
shellCommand(`pnpm -C ${testPackageDir} install-test`)
]
})
]
}
]