Skip to content

Commit b4552ce

Browse files
committed
test: avoid potential output conflict
1 parent b38e48b commit b4552ce

File tree

4 files changed

+81
-43
lines changed

4 files changed

+81
-43
lines changed

scripts/dictionary.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ unpatch
135135
unplugin
136136
unpredictibly
137137
unshift
138+
unstub
138139
upath
139140
vitest
140141
vnode

tests/integration/cli/build.test.ts

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,52 +2,63 @@ import { execSync } from 'node:child_process';
22
import path from 'node:path';
33
import fse from 'fs-extra';
44
import { globContentJSON } from 'test-helper';
5-
import { describe, expect, test } from 'vitest';
5+
import { afterAll, beforeAll, describe, expect, test, vi } from 'vitest';
6+
7+
const DIR = 'build';
8+
const DIST_DIR = path.join(__dirname, 'dist', DIR);
9+
10+
beforeAll(() => {
11+
vi.stubEnv('RSLIB_TEST_OUT_DIR', DIR);
12+
});
13+
14+
afterAll(() => {
15+
vi.unstubAllEnvs();
16+
});
617

718
describe('build command', async () => {
819
test('basic', async () => {
9-
await fse.remove(path.join(__dirname, 'dist'));
20+
await fse.remove(DIST_DIR);
1021
execSync('npx rslib build', {
1122
cwd: __dirname,
1223
});
1324

14-
const files = await globContentJSON(path.join(__dirname, 'dist'));
25+
const files = await globContentJSON(DIST_DIR);
1526
const fileNames = Object.keys(files).sort();
1627
expect(fileNames).toMatchInlineSnapshot(`
1728
[
18-
"<ROOT>/tests/integration/cli/dist/cjs/index.cjs",
19-
"<ROOT>/tests/integration/cli/dist/esm/index.js",
29+
"<ROOT>/tests/integration/cli/dist/build/index.cjs",
30+
"<ROOT>/tests/integration/cli/dist/build/index.js",
2031
]
2132
`);
2233
});
2334

2435
test('--lib', async () => {
25-
await fse.remove(path.join(__dirname, 'dist'));
36+
await fse.remove(DIST_DIR);
2637
execSync('npx rslib build --lib esm', {
2738
cwd: __dirname,
2839
});
2940

30-
const files = await globContentJSON(path.join(__dirname, 'dist'));
41+
const files = await globContentJSON(DIST_DIR);
3142
const fileNames = Object.keys(files).sort();
3243
expect(fileNames).toMatchInlineSnapshot(`
3344
[
34-
"<ROOT>/tests/integration/cli/dist/esm/index.js",
45+
"<ROOT>/tests/integration/cli/dist/build/index.js",
3546
]
3647
`);
3748
});
3849

3950
test('--lib multiple', async () => {
40-
await fse.remove(path.join(__dirname, 'dist'));
51+
await fse.remove(DIST_DIR);
4152
execSync('npx rslib build --lib esm --lib cjs', {
4253
cwd: __dirname,
4354
});
4455

45-
const files = await globContentJSON(path.join(__dirname, 'dist'));
56+
const files = await globContentJSON(DIST_DIR);
4657
const fileNames = Object.keys(files).sort();
4758
expect(fileNames).toMatchInlineSnapshot(`
4859
[
49-
"<ROOT>/tests/integration/cli/dist/cjs/index.cjs",
50-
"<ROOT>/tests/integration/cli/dist/esm/index.js",
60+
"<ROOT>/tests/integration/cli/dist/build/index.cjs",
61+
"<ROOT>/tests/integration/cli/dist/build/index.js",
5162
]
5263
`);
5364
});
@@ -73,7 +84,6 @@ describe('build command', async () => {
7384

7485
test('--root', async () => {
7586
await fse.remove(path.join(__dirname, 'dist'));
76-
console.log('__dirname: ', __dirname);
7787
execSync('npx rslib build --root custom-root', {
7888
cwd: __dirname,
7989
});
Lines changed: 37 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,38 @@
11
import { execSync } from 'node:child_process';
22
import path from 'node:path';
3-
import { describe } from 'node:test';
43
import fse from 'fs-extra';
54
import { globContentJSON } from 'test-helper';
6-
import { expect, test } from 'vitest';
5+
import { afterAll, beforeAll, describe, expect, test, vi } from 'vitest';
6+
7+
const DIR = 'inspect';
8+
const DIST_DIR = path.join(__dirname, 'dist', DIR);
9+
10+
beforeAll(() => {
11+
vi.stubEnv('RSLIB_TEST_OUT_DIR', DIR);
12+
});
13+
14+
afterAll(() => {
15+
vi.unstubAllEnvs();
16+
});
717

818
describe('inspect command', async () => {
919
test('basic', async () => {
10-
await fse.remove(path.join(__dirname, 'dist'));
20+
await fse.remove(DIST_DIR);
1121
execSync('npx rslib inspect', {
1222
cwd: __dirname,
1323
});
1424

15-
const files = await globContentJSON(path.join(__dirname, 'dist/.rsbuild'));
25+
const files = await globContentJSON(path.join(DIST_DIR, '.rsbuild'));
1626
const fileNames = Object.keys(files).sort();
1727

1828
expect(fileNames).toMatchInlineSnapshot(`
19-
[
20-
"<ROOT>/tests/integration/cli/dist/.rsbuild/rsbuild.config.cjs.mjs",
21-
"<ROOT>/tests/integration/cli/dist/.rsbuild/rsbuild.config.esm.mjs",
22-
"<ROOT>/tests/integration/cli/dist/.rsbuild/rspack.config.cjs.mjs",
23-
"<ROOT>/tests/integration/cli/dist/.rsbuild/rspack.config.esm.mjs",
24-
]
25-
`);
29+
[
30+
"<ROOT>/tests/integration/cli/dist/inspect/.rsbuild/rsbuild.config.cjs.mjs",
31+
"<ROOT>/tests/integration/cli/dist/inspect/.rsbuild/rsbuild.config.esm.mjs",
32+
"<ROOT>/tests/integration/cli/dist/inspect/.rsbuild/rspack.config.cjs.mjs",
33+
"<ROOT>/tests/integration/cli/dist/inspect/.rsbuild/rspack.config.esm.mjs",
34+
]
35+
`);
2636

2737
// esm rsbuild config
2838
const rsbuildConfigEsm = fileNames.find((item) =>
@@ -40,23 +50,21 @@ describe('inspect command', async () => {
4050
});
4151

4252
test('--lib', async () => {
43-
await fse.remove(path.join(__dirname, 'dist'));
53+
await fse.remove(DIST_DIR);
4454
execSync('npx rslib inspect --lib esm', {
4555
cwd: __dirname,
4656
});
4757

48-
const files = await globContentJSON(
49-
path.join(__dirname, 'dist/esm/.rsbuild'),
50-
);
58+
const files = await globContentJSON(path.join(DIST_DIR, '.rsbuild'));
5159
const fileNames = Object.keys(files).sort();
5260

5361
// Rsbuild will emit dump files to `dist/esm` if only one environment is specified.
5462
expect(fileNames).toMatchInlineSnapshot(`
55-
[
56-
"<ROOT>/tests/integration/cli/dist/esm/.rsbuild/rsbuild.config.mjs",
57-
"<ROOT>/tests/integration/cli/dist/esm/.rsbuild/rspack.config.esm.mjs",
58-
]
59-
`);
63+
[
64+
"<ROOT>/tests/integration/cli/dist/inspect/.rsbuild/rsbuild.config.mjs",
65+
"<ROOT>/tests/integration/cli/dist/inspect/.rsbuild/rspack.config.esm.mjs",
66+
]
67+
`);
6068

6169
// esm rsbuild config
6270
const rsbuildConfigEsm = fileNames.find((item) =>
@@ -74,22 +82,22 @@ describe('inspect command', async () => {
7482
});
7583

7684
test('--lib multiple', async () => {
77-
await fse.remove(path.join(__dirname, 'dist'));
85+
await fse.remove(DIST_DIR);
7886
execSync('npx rslib inspect --lib esm --lib cjs', {
7987
cwd: __dirname,
8088
});
8189

82-
const files = await globContentJSON(path.join(__dirname, 'dist/.rsbuild'));
90+
const files = await globContentJSON(path.join(DIST_DIR, '.rsbuild'));
8391
const fileNames = Object.keys(files).sort();
8492

8593
// Rsbuild will emit dump files to `dist/esm` if only one environment is specified.
8694
expect(fileNames).toMatchInlineSnapshot(`
87-
[
88-
"<ROOT>/tests/integration/cli/dist/.rsbuild/rsbuild.config.cjs.mjs",
89-
"<ROOT>/tests/integration/cli/dist/.rsbuild/rsbuild.config.esm.mjs",
90-
"<ROOT>/tests/integration/cli/dist/.rsbuild/rspack.config.cjs.mjs",
91-
"<ROOT>/tests/integration/cli/dist/.rsbuild/rspack.config.esm.mjs",
92-
]
93-
`);
95+
[
96+
"<ROOT>/tests/integration/cli/dist/inspect/.rsbuild/rsbuild.config.cjs.mjs",
97+
"<ROOT>/tests/integration/cli/dist/inspect/.rsbuild/rsbuild.config.esm.mjs",
98+
"<ROOT>/tests/integration/cli/dist/inspect/.rsbuild/rspack.config.cjs.mjs",
99+
"<ROOT>/tests/integration/cli/dist/inspect/.rsbuild/rspack.config.esm.mjs",
100+
]
101+
`);
94102
});
95103
});
Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,25 @@
11
import { defineConfig } from '@rslib/core';
22
import { generateBundleCjsConfig, generateBundleEsmConfig } from 'test-helper';
33

4+
const ROOT = process.env.RSLIB_TEST_OUT_DIR
5+
? `dist/${process.env.RSLIB_TEST_OUT_DIR}`
6+
: 'dist/inspect';
7+
48
export default defineConfig({
5-
lib: [generateBundleEsmConfig(), generateBundleCjsConfig()],
9+
lib: [
10+
generateBundleEsmConfig({
11+
output: {
12+
distPath: {
13+
root: ROOT,
14+
},
15+
},
16+
}),
17+
generateBundleCjsConfig({
18+
output: {
19+
distPath: {
20+
root: ROOT,
21+
},
22+
},
23+
}),
24+
],
625
});

0 commit comments

Comments
 (0)