Skip to content

Commit 3244725

Browse files
authored
fix: windows ci (#82)
1 parent 172b1f3 commit 3244725

File tree

10 files changed

+115
-84
lines changed

10 files changed

+115
-84
lines changed

.github/workflows/test-ubuntu.yml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,13 @@ jobs:
9999
if: steps.changes.outputs.changed == 'true'
100100
run: pnpm install && cd ./e2e && pnpx playwright install
101101

102-
- name: E2E Test
102+
- name: E2E Artifact Test (Vitest)
103103
if: steps.changes.outputs.changed == 'true'
104-
run: |
105-
pnpm run test:artifact
106-
pnpm run test:e2e
104+
run: pnpm run test:artifact
105+
106+
- name: E2E Test (Playwright)
107+
if: steps.changes.outputs.changed == 'true'
108+
run: pnpm run test:e2e
107109

108110
- name: Examples Test
109111
if: steps.changes.outputs.changed == 'true'

.github/workflows/test-windows.yml

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -108,13 +108,14 @@ jobs:
108108
if: steps.changes.outputs.changed == 'true'
109109
run: pnpm install && cd ./e2e && npx playwright install
110110

111-
- name: E2E Test
111+
- name: E2E Artifact Test (Vitest)
112112
if: steps.changes.outputs.changed == 'true'
113-
run: |
114-
pnpm run test:artifact
115-
pnpm run test:e2e
113+
run: pnpm run test:artifact
114+
115+
- name: E2E Test (Playwright)
116+
if: steps.changes.outputs.changed == 'true'
117+
run: pnpm run test:e2e
116118

117119
- name: Examples Test
118120
if: steps.changes.outputs.changed == 'true'
119-
run: |
120-
pnpm run build:examples
121+
run: pnpm run build:examples

e2e/cases/bundle-false/index.test.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,18 @@ test('basic', async () => {
88

99
expect(files.esm).toMatchInlineSnapshot(`
1010
[
11-
"./dist/esm/index.js",
12-
"./dist/esm/sum.js",
13-
"./dist/esm/utils/numbers.js",
14-
"./dist/esm/utils/strings.js",
11+
"<ROOT>/e2e/cases/bundle-false/basic/dist/esm/index.js",
12+
"<ROOT>/e2e/cases/bundle-false/basic/dist/esm/sum.js",
13+
"<ROOT>/e2e/cases/bundle-false/basic/dist/esm/utils/numbers.js",
14+
"<ROOT>/e2e/cases/bundle-false/basic/dist/esm/utils/strings.js",
1515
]
1616
`);
1717
expect(files.cjs).toMatchInlineSnapshot(`
1818
[
19-
"./dist/cjs/index.js",
20-
"./dist/cjs/sum.js",
21-
"./dist/cjs/utils/numbers.js",
22-
"./dist/cjs/utils/strings.js",
19+
"<ROOT>/e2e/cases/bundle-false/basic/dist/cjs/index.js",
20+
"<ROOT>/e2e/cases/bundle-false/basic/dist/cjs/sum.js",
21+
"<ROOT>/e2e/cases/bundle-false/basic/dist/cjs/utils/numbers.js",
22+
"<ROOT>/e2e/cases/bundle-false/basic/dist/cjs/utils/strings.js",
2323
]
2424
`);
2525
});
@@ -30,12 +30,12 @@ test('single file', async () => {
3030

3131
expect(files.esm).toMatchInlineSnapshot(`
3232
[
33-
"./dist/esm/index.js",
33+
"<ROOT>/e2e/cases/bundle-false/single-file/dist/esm/index.js",
3434
]
3535
`);
3636
expect(files.cjs).toMatchInlineSnapshot(`
3737
[
38-
"./dist/cjs/index.js",
38+
"<ROOT>/e2e/cases/bundle-false/single-file/dist/cjs/index.js",
3939
]
4040
`);
4141
});

e2e/cases/dts/__snapshots__/index.test.ts.snap

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,25 @@
22

33
exports[`dts when bundle: false > basic 2`] = `
44
{
5-
"./dist/esm/index.d.ts": "export * from './utils/numbers';
5+
"<ROOT>/e2e/cases/dts/bundle-false/basic/dist/esm/index.d.ts": "export * from './utils/numbers';
66
export * from './utils/strings';
77
export * from './sum';
88
",
9-
"./dist/esm/sum.d.ts": "export declare const numSum: number;
9+
"<ROOT>/e2e/cases/dts/bundle-false/basic/dist/esm/sum.d.ts": "export declare const numSum: number;
1010
export declare const strSum: string;
1111
",
12-
"./dist/esm/utils/numbers.d.ts": "export declare const num1 = 1;
12+
"<ROOT>/e2e/cases/dts/bundle-false/basic/dist/esm/utils/numbers.d.ts": "export declare const num1 = 1;
1313
export declare const num2 = 2;
1414
export declare const num3 = 3;
1515
",
16-
"./dist/esm/utils/strings.d.ts": "export declare const str1 = "str1";
16+
"<ROOT>/e2e/cases/dts/bundle-false/basic/dist/esm/utils/strings.d.ts": "export declare const str1 = "str1";
1717
export declare const str2 = "str2";
1818
export declare const str3 = "str3";
1919
",
2020
}
2121
`;
2222

23-
exports[`dts when bundle: true > basic 1`] = `
23+
exports[`dts when bundle: true > basic 2`] = `
2424
{
2525
"esm": "export declare const num1 = 1;
2626

e2e/cases/dts/index.test.ts

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ describe('dts when bundle: false', () => {
99

1010
expect(files.esm).toMatchInlineSnapshot(`
1111
[
12-
"./dist/esm/index.d.ts",
13-
"./dist/esm/sum.d.ts",
14-
"./dist/esm/utils/numbers.d.ts",
15-
"./dist/esm/utils/strings.d.ts",
12+
"<ROOT>/e2e/cases/dts/bundle-false/basic/dist/esm/index.d.ts",
13+
"<ROOT>/e2e/cases/dts/bundle-false/basic/dist/esm/sum.d.ts",
14+
"<ROOT>/e2e/cases/dts/bundle-false/basic/dist/esm/utils/numbers.d.ts",
15+
"<ROOT>/e2e/cases/dts/bundle-false/basic/dist/esm/utils/strings.d.ts",
1616
]
1717
`);
1818
expect(contents.esm).toMatchSnapshot();
@@ -22,7 +22,7 @@ describe('dts when bundle: false', () => {
2222
const fixturePath = join(__dirname, 'bundle-false', 'false');
2323
const { files } = await buildAndGetResults(fixturePath, 'dts');
2424

25-
expect(files.esm).toBe(undefined);
25+
expect(files.esm).toMatchInlineSnapshot('undefined');
2626
});
2727

2828
test('distPath', async () => {
@@ -31,10 +31,10 @@ describe('dts when bundle: false', () => {
3131

3232
expect(files.esm).toMatchInlineSnapshot(`
3333
[
34-
"./dist/custom/index.d.ts",
35-
"./dist/custom/sum.d.ts",
36-
"./dist/custom/utils/numbers.d.ts",
37-
"./dist/custom/utils/strings.d.ts",
34+
"<ROOT>/e2e/cases/dts/bundle-false/dist-path/dist/custom/index.d.ts",
35+
"<ROOT>/e2e/cases/dts/bundle-false/dist-path/dist/custom/sum.d.ts",
36+
"<ROOT>/e2e/cases/dts/bundle-false/dist-path/dist/custom/utils/numbers.d.ts",
37+
"<ROOT>/e2e/cases/dts/bundle-false/dist-path/dist/custom/utils/strings.d.ts",
3838
]
3939
`);
4040
});
@@ -52,10 +52,10 @@ describe('dts when bundle: false', () => {
5252

5353
expect(files.cjs).toMatchInlineSnapshot(`
5454
[
55-
"./dist/cjs/index.d.cts",
56-
"./dist/cjs/sum.d.cts",
57-
"./dist/cjs/utils/numbers.d.cts",
58-
"./dist/cjs/utils/strings.d.cts",
55+
"<ROOT>/e2e/cases/dts/bundle-false/auto-extension/dist/cjs/index.d.cts",
56+
"<ROOT>/e2e/cases/dts/bundle-false/auto-extension/dist/cjs/sum.d.cts",
57+
"<ROOT>/e2e/cases/dts/bundle-false/auto-extension/dist/cjs/utils/numbers.d.cts",
58+
"<ROOT>/e2e/cases/dts/bundle-false/auto-extension/dist/cjs/utils/strings.d.cts",
5959
]
6060
`);
6161
});
@@ -69,22 +69,26 @@ describe('dts when bundle: true', () => {
6969
'dts',
7070
);
7171

72-
expect(entryFiles.esm).toEqual('./dist/esm/main.d.ts');
72+
expect(entryFiles.esm).toMatchInlineSnapshot(
73+
`"<ROOT>/e2e/cases/dts/bundle/basic/dist/esm/main.d.ts"`,
74+
);
7375
expect(entries).toMatchSnapshot();
7476
});
7577

7678
test('dts false', async () => {
7779
const fixturePath = join(__dirname, 'bundle', 'false');
7880
const { entryFiles } = await buildAndGetResults(fixturePath, 'dts');
7981

80-
expect(entryFiles.esm).toEqual(undefined);
82+
expect(entryFiles.esm).toMatchInlineSnapshot('undefined');
8183
});
8284

8385
test('distPath', async () => {
8486
const fixturePath = join(__dirname, 'bundle', 'dist-path');
8587
const { entryFiles } = await buildAndGetResults(fixturePath, 'dts');
8688

87-
expect(entryFiles.esm).toEqual('./dist/custom/main.d.ts');
89+
expect(entryFiles.esm).toMatchInlineSnapshot(
90+
`"<ROOT>/e2e/cases/dts/bundle/dist-path/dist/custom/main.d.ts"`,
91+
);
8892
});
8993

9094
test('abortOnError: false', async () => {
@@ -98,13 +102,17 @@ describe('dts when bundle: true', () => {
98102
const fixturePath = join(__dirname, 'bundle', 'auto-extension');
99103
const { entryFiles } = await buildAndGetResults(fixturePath, 'dts');
100104

101-
expect(entryFiles.cjs).toEqual('./dist/cjs/main.d.cts');
105+
expect(entryFiles.cjs).toMatchInlineSnapshot(
106+
`"<ROOT>/e2e/cases/dts/bundle/auto-extension/dist/cjs/main.d.cts"`,
107+
);
102108
});
103109

104110
test('bundleName -- set source.entry', async () => {
105111
const fixturePath = join(__dirname, 'bundle', 'bundle-name');
106112
const { entryFiles } = await buildAndGetResults(fixturePath, 'dts');
107113

108-
expect(entryFiles.esm).toEqual('./dist/esm/bundleName.d.ts');
114+
expect(entryFiles.esm).toMatchInlineSnapshot(
115+
`"<ROOT>/e2e/cases/dts/bundle/bundle-name/dist/esm/bundleName.d.ts"`,
116+
);
109117
});
110118
});

e2e/scripts/helper.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ import fg, {
66
} from 'fast-glob';
77
import fse from 'fs-extra';
88

9-
export const getFiles = async (_pattern: string) => {};
10-
119
// fast-glob only accepts posix path
1210
// https://github.com/mrmlnc/fast-glob#convertpathtopatternpath
1311
const convertPath = (path: string) => {
@@ -17,7 +15,10 @@ const convertPath = (path: string) => {
1715
return path;
1816
};
1917

20-
export const globContentJSON = async (path: string, options?: GlobOptions) => {
18+
export const globContentJSON = async (
19+
path: string,
20+
options?: GlobOptions,
21+
): Promise<Record<string, string>> => {
2122
const files = await fg(convertPath(join(path, '**/*')), options);
2223
const ret: Record<string, string> = {};
2324

e2e/scripts/shared.ts

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { join } from 'node:path';
1+
import { isAbsolute, join } from 'node:path';
22
import {
33
type InspectConfigResult,
44
mergeRsbuildConfig as mergeConfig,
@@ -39,11 +39,25 @@ export function generateBundleCjsConfig(
3939
return mergeConfig(cjsBasicConfig, config)!;
4040
}
4141

42+
type FormatType = 'esm' | 'cjs';
43+
type FilePath = string;
44+
45+
type BuildResult = {
46+
files: Record<FormatType, FilePath[]>;
47+
contents: Record<FormatType, Record<FilePath, string>>;
48+
entries: Record<FormatType, string>;
49+
entryFiles: Record<FormatType, FilePath>;
50+
51+
rspackConfig: InspectConfigResult['origin']['bundlerConfigs'];
52+
rsbuildConfig: InspectConfigResult['origin']['rsbuildConfig'];
53+
isSuccess: boolean;
54+
};
55+
4256
export async function getResults(
4357
rslibConfig: RslibConfig,
4458
fixturePath: string,
4559
type: 'js' | 'dts',
46-
) {
60+
): Promise<Omit<BuildResult, 'rspackConfig' | 'rsbuildConfig' | 'isSuccess'>> {
4761
const files: Record<string, string[]> = {};
4862
const contents: Record<string, Record<string, string>> = {};
4963
const entries: Record<string, string> = {};
@@ -62,18 +76,11 @@ export async function getResults(
6276

6377
const regex = type === 'dts' ? /\.d.(ts|cts|mts)$/ : /\.(js|cjs|mjs)$/;
6478

65-
const rawContent = await globContentJSON(globFolder, {
79+
const content: Record<string, string> = await globContentJSON(globFolder, {
6680
absolute: true,
67-
ignore: ['/**/*.map'],
81+
ignore: ['**/*.map'],
6882
});
6983

70-
const content: Record<string, string> = {};
71-
72-
for (const key of Object.keys(rawContent)) {
73-
const newKey = key.replace(fixturePath, '.');
74-
content[newKey] = rawContent[key]!;
75-
}
76-
7784
const fileSet = Object.keys(content).filter((file) => regex.test(file));
7885
const filterContent: Record<string, string> = {};
7986
for (const key of fileSet) {
@@ -102,16 +109,6 @@ export async function getResults(
102109
};
103110
}
104111

105-
type BuildResult = {
106-
contents: Record<string, Record<string, string>>;
107-
files: Record<string, string[]>;
108-
entries: Record<string, string>;
109-
entryFiles: Record<string, string>;
110-
rspackConfig: InspectConfigResult['origin']['bundlerConfigs'];
111-
rsbuildConfig: InspectConfigResult['origin']['rsbuildConfig'];
112-
isSuccess: boolean;
113-
};
114-
115112
export async function buildAndGetResults(
116113
fixturePath: string,
117114
type: 'all',

packages/core/src/utils/helper.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,12 @@ async function calcLongestCommonPath(
7878
return null;
7979
}
8080

81-
const splitPaths = absPaths.map((p) => p.split(path.sep));
81+
// we support two cases
82+
// 1. /packages-a/src/index.ts
83+
// 2. D:/packages-a/src/index.ts
84+
const sep = path.posix.sep as '/';
85+
86+
const splitPaths = absPaths.map((p) => p.split(sep));
8287
let lcaFragments = splitPaths[0]!;
8388
for (let i = 1; i < splitPaths.length; i++) {
8489
const currentPath = splitPaths[i]!;
@@ -92,7 +97,7 @@ async function calcLongestCommonPath(
9297
lcaFragments = lcaFragments.slice(0, j);
9398
}
9499

95-
let lca = lcaFragments.length > 0 ? lcaFragments.join(path.sep) : '/';
100+
let lca = lcaFragments.length > 0 ? lcaFragments.join(sep) : sep;
96101

97102
const stats = await fsP.stat(lca);
98103
if (stats?.isFile()) {

packages/core/tests/lcp.test.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ describe('LCP calculate correctly', () => {
2929
expect(result).toEqual('/Users/Someone/project-a/src');
3030
} else {
3131
const result = await calcLongestCommonPath([
32-
'D:\\Users\\Someone\\project-a\\src\\helpers',
33-
'D:\\Users\\Someone\\project-a\\src',
34-
'D:\\Users\\Someone\\project-a\\src\\utils',
32+
'D:/Users/Someone/project-a/src/helpers',
33+
'D:/Users/Someone/project-a/src',
34+
'D:/Users/Someone/project-a/src/utils',
3535
]);
36-
expect(result).toEqual('D:\\Users\\Someone\\project-a\\src');
36+
expect(result).toEqual('D:/Users/Someone/project-a/src');
3737
}
3838
});
3939

@@ -49,11 +49,11 @@ describe('LCP calculate correctly', () => {
4949
expect(result).toEqual('/Users/Someone/project-monorepo');
5050
} else {
5151
const result = await calcLongestCommonPath([
52-
'D:\\Users\\Someone\\project-monorepo\\packages-a\\src\\index.ts',
53-
'D:\\Users\\Someone\\project-monorepo\\packages-util\\src\\index.js',
54-
'D:\\Users\\Someone\\project-monorepo\\script.js',
52+
'D:/Users/Someone/project-monorepo/packages-a/src/index.ts',
53+
'D:/Users/Someone/project-monorepo/packages-util/src/index.js',
54+
'D:/Users/Someone/project-monorepo/script.js',
5555
]);
56-
expect(result).toEqual('D:\\Users\\Someone\\project-monorepo');
56+
expect(result).toEqual('D:/Users/Someone/project-monorepo');
5757
}
5858
});
5959

@@ -68,9 +68,9 @@ describe('LCP calculate correctly', () => {
6868
expect(result).toEqual('/Users/Someone/project/src');
6969
} else {
7070
const result = await calcLongestCommonPath([
71-
'D:\\Users\\Someone\\project\\src\\index.js',
71+
'D:/Users/Someone/project/src/index.js',
7272
]);
73-
expect(result).toEqual('D:\\Users\\Someone\\project\\src');
73+
expect(result).toEqual('D:/Users/Someone/project/src');
7474
}
7575
});
7676
});

0 commit comments

Comments
 (0)