Skip to content

Commit 04d48ee

Browse files
committed
test: refactor npm pack test
1 parent 2f2b709 commit 04d48ee

File tree

1 file changed

+62
-8
lines changed

1 file changed

+62
-8
lines changed

test/package.test.js

+62-8
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,77 @@
1313
// limitations under the License.
1414

1515
import assert from 'node:assert'
16-
import { test, describe, beforeEach, before, after } from 'node:test'
16+
import { test, describe, after, before } from 'node:test'
1717
import '../build/globals.js'
1818

19+
const __dirname = new URL('.', import.meta.url).pathname
20+
const root = path.resolve(__dirname, '..')
21+
1922
describe('package', () => {
20-
before(() => syncProcessCwd())
21-
after(() => syncProcessCwd(false))
22-
beforeEach(async () => {
23+
before(async () => {
2324
const pack = await $`npm pack`
2425
await $`tar xf ${pack}`
2526
await $`rm ${pack}`.nothrow()
2627
})
28+
after(async () => {
29+
await $`rm -rf package`
30+
})
31+
32+
test('content looks fine', async () => {
33+
const files = await glob('**/*', {
34+
cwd: path.resolve(root, 'package'),
35+
absolute: false,
36+
onlyFiles: true,
37+
})
38+
assert.deepEqual(
39+
files.sort(),
40+
[
41+
'LICENSE',
42+
'README.md',
43+
'package.json',
44+
'man/zx.1',
45+
'build/cli.cjs',
46+
'build/cli.d.ts',
47+
'build/cli.js',
48+
'build/core.cjs',
49+
'build/core.d.ts',
50+
'build/core.js',
51+
'build/deno.js',
52+
'build/deps.cjs',
53+
'build/deps.d.ts',
54+
'build/deps.js',
55+
'build/esblib.cjs',
56+
'build/globals.cjs',
57+
'build/globals.d.ts',
58+
'build/globals.js',
59+
'build/goods.cjs',
60+
'build/goods.d.ts',
61+
'build/goods.js',
62+
'build/index.cjs',
63+
'build/index.d.ts',
64+
'build/index.js',
65+
'build/repl.cjs',
66+
'build/repl.d.ts',
67+
'build/repl.js',
68+
'build/util.cjs',
69+
'build/util.d.ts',
70+
'build/util.js',
71+
'build/vendor-core.cjs',
72+
'build/vendor-core.d.ts',
73+
'build/vendor-core.js',
74+
'build/vendor-extra.cjs',
75+
'build/vendor-extra.d.ts',
76+
'build/vendor-extra.js',
77+
'build/vendor.cjs',
78+
'build/vendor.d.ts',
79+
'build/vendor.js',
80+
].sort()
81+
)
82+
})
2783

2884
test('ts project', async () => {
29-
const pack = path.resolve('package')
3085
const out = await within(async () => {
31-
cd('test/fixtures/ts-project')
86+
$.cwd = path.resolve(__dirname, 'fixtures/ts-project')
3287
await $`npm i --no-package-lock`
3388
try {
3489
await $`npx tsc`
@@ -41,9 +96,8 @@ describe('package', () => {
4196
})
4297

4398
test('js project with zx', async () => {
44-
const pack = path.resolve('package')
4599
const out = await within(async () => {
46-
cd('test/fixtures/js-project')
100+
$.cwd = path.resolve(__dirname, 'fixtures/js-project')
47101
await $`npm i --no-package-lock`
48102
return $`node node_modules/zx/build/cli.js --verbose script.js`
49103
})

0 commit comments

Comments
 (0)