forked from pnpm/cmd-shim
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.js
46 lines (42 loc) · 1.24 KB
/
setup.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
'use strict'
/** @type {typeof import("fs")} */
// @ts-ignore
const memfs = require('memfs')
const path = require('path')
const { fixtures, fixtures2 } = process.platform === 'win32' ? {
fixtures: 'I:\\cmd-shim\\fixtures',
fixtures2: 'J:\\cmd-shim\\fixtures'
} : {
fixtures: '/foo/cmd-shim/fixtures',
fixtures2: '/bar/cmd-shim/fixtures'
}
exports.fixtures = fixtures
exports.fixtures2 = fixtures2
exports.fs = memfs
/** @type {{ [dir: string]: { [filename: string]: string } }} */
const fixtureFiles = {
[fixtures]: {
'src.exe': 'exe',
'src.env': '#!/usr/bin/env node\nconsole.log(/hi/)\n',
'src.env.args': '#!/usr/bin/env node --expose_gc\ngc()\n',
'src.sh': '#!/usr/bin/sh\necho hi\n',
'src.sh.args': '#!/usr/bin/sh -x\necho hi\n',
'from.env.S': '#!/usr/bin/env -S node --expose_gc\ngc()\n'
},
[fixtures2]: {
'src.sh.args': '#!/usr/bin/sh -x\necho hi\n'
}
}
beforeAll(() => {
const fs = memfs.promises
return Promise.all(
Object.entries(fixtureFiles).map(async ([dir, files]) => {
await fs.mkdir(dir, { recursive: true })
return Promise.all(
Object.entries(files).map(([filename, contents]) => {
return fs.writeFile(path.join(dir, filename), contents)
})
)
})
)
})