Skip to content

Commit

Permalink
fix: windows ci (#82)
Browse files Browse the repository at this point in the history
  • Loading branch information
SoonIter authored Aug 13, 2024
1 parent 172b1f3 commit 3244725
Show file tree
Hide file tree
Showing 10 changed files with 115 additions and 84 deletions.
10 changes: 6 additions & 4 deletions .github/workflows/test-ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,13 @@ jobs:
if: steps.changes.outputs.changed == 'true'
run: pnpm install && cd ./e2e && pnpx playwright install

- name: E2E Test
- name: E2E Artifact Test (Vitest)
if: steps.changes.outputs.changed == 'true'
run: |
pnpm run test:artifact
pnpm run test:e2e
run: pnpm run test:artifact

- name: E2E Test (Playwright)
if: steps.changes.outputs.changed == 'true'
run: pnpm run test:e2e

- name: Examples Test
if: steps.changes.outputs.changed == 'true'
Expand Down
13 changes: 7 additions & 6 deletions .github/workflows/test-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,14 @@ jobs:
if: steps.changes.outputs.changed == 'true'
run: pnpm install && cd ./e2e && npx playwright install

- name: E2E Test
- name: E2E Artifact Test (Vitest)
if: steps.changes.outputs.changed == 'true'
run: |
pnpm run test:artifact
pnpm run test:e2e
run: pnpm run test:artifact

- name: E2E Test (Playwright)
if: steps.changes.outputs.changed == 'true'
run: pnpm run test:e2e

- name: Examples Test
if: steps.changes.outputs.changed == 'true'
run: |
pnpm run build:examples
run: pnpm run build:examples
20 changes: 10 additions & 10 deletions e2e/cases/bundle-false/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@ test('basic', async () => {

expect(files.esm).toMatchInlineSnapshot(`
[
"./dist/esm/index.js",
"./dist/esm/sum.js",
"./dist/esm/utils/numbers.js",
"./dist/esm/utils/strings.js",
"<ROOT>/e2e/cases/bundle-false/basic/dist/esm/index.js",
"<ROOT>/e2e/cases/bundle-false/basic/dist/esm/sum.js",
"<ROOT>/e2e/cases/bundle-false/basic/dist/esm/utils/numbers.js",
"<ROOT>/e2e/cases/bundle-false/basic/dist/esm/utils/strings.js",
]
`);
expect(files.cjs).toMatchInlineSnapshot(`
[
"./dist/cjs/index.js",
"./dist/cjs/sum.js",
"./dist/cjs/utils/numbers.js",
"./dist/cjs/utils/strings.js",
"<ROOT>/e2e/cases/bundle-false/basic/dist/cjs/index.js",
"<ROOT>/e2e/cases/bundle-false/basic/dist/cjs/sum.js",
"<ROOT>/e2e/cases/bundle-false/basic/dist/cjs/utils/numbers.js",
"<ROOT>/e2e/cases/bundle-false/basic/dist/cjs/utils/strings.js",
]
`);
});
Expand All @@ -30,12 +30,12 @@ test('single file', async () => {

expect(files.esm).toMatchInlineSnapshot(`
[
"./dist/esm/index.js",
"<ROOT>/e2e/cases/bundle-false/single-file/dist/esm/index.js",
]
`);
expect(files.cjs).toMatchInlineSnapshot(`
[
"./dist/cjs/index.js",
"<ROOT>/e2e/cases/bundle-false/single-file/dist/cjs/index.js",
]
`);
});
10 changes: 5 additions & 5 deletions e2e/cases/dts/__snapshots__/index.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,25 @@

exports[`dts when bundle: false > basic 2`] = `
{
"./dist/esm/index.d.ts": "export * from './utils/numbers';
"<ROOT>/e2e/cases/dts/bundle-false/basic/dist/esm/index.d.ts": "export * from './utils/numbers';
export * from './utils/strings';
export * from './sum';
",
"./dist/esm/sum.d.ts": "export declare const numSum: number;
"<ROOT>/e2e/cases/dts/bundle-false/basic/dist/esm/sum.d.ts": "export declare const numSum: number;
export declare const strSum: string;
",
"./dist/esm/utils/numbers.d.ts": "export declare const num1 = 1;
"<ROOT>/e2e/cases/dts/bundle-false/basic/dist/esm/utils/numbers.d.ts": "export declare const num1 = 1;
export declare const num2 = 2;
export declare const num3 = 3;
",
"./dist/esm/utils/strings.d.ts": "export declare const str1 = "str1";
"<ROOT>/e2e/cases/dts/bundle-false/basic/dist/esm/utils/strings.d.ts": "export declare const str1 = "str1";
export declare const str2 = "str2";
export declare const str3 = "str3";
",
}
`;

exports[`dts when bundle: true > basic 1`] = `
exports[`dts when bundle: true > basic 2`] = `
{
"esm": "export declare const num1 = 1;
Expand Down
44 changes: 26 additions & 18 deletions e2e/cases/dts/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ describe('dts when bundle: false', () => {

expect(files.esm).toMatchInlineSnapshot(`
[
"./dist/esm/index.d.ts",
"./dist/esm/sum.d.ts",
"./dist/esm/utils/numbers.d.ts",
"./dist/esm/utils/strings.d.ts",
"<ROOT>/e2e/cases/dts/bundle-false/basic/dist/esm/index.d.ts",
"<ROOT>/e2e/cases/dts/bundle-false/basic/dist/esm/sum.d.ts",
"<ROOT>/e2e/cases/dts/bundle-false/basic/dist/esm/utils/numbers.d.ts",
"<ROOT>/e2e/cases/dts/bundle-false/basic/dist/esm/utils/strings.d.ts",
]
`);
expect(contents.esm).toMatchSnapshot();
Expand All @@ -22,7 +22,7 @@ describe('dts when bundle: false', () => {
const fixturePath = join(__dirname, 'bundle-false', 'false');
const { files } = await buildAndGetResults(fixturePath, 'dts');

expect(files.esm).toBe(undefined);
expect(files.esm).toMatchInlineSnapshot('undefined');
});

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

expect(files.esm).toMatchInlineSnapshot(`
[
"./dist/custom/index.d.ts",
"./dist/custom/sum.d.ts",
"./dist/custom/utils/numbers.d.ts",
"./dist/custom/utils/strings.d.ts",
"<ROOT>/e2e/cases/dts/bundle-false/dist-path/dist/custom/index.d.ts",
"<ROOT>/e2e/cases/dts/bundle-false/dist-path/dist/custom/sum.d.ts",
"<ROOT>/e2e/cases/dts/bundle-false/dist-path/dist/custom/utils/numbers.d.ts",
"<ROOT>/e2e/cases/dts/bundle-false/dist-path/dist/custom/utils/strings.d.ts",
]
`);
});
Expand All @@ -52,10 +52,10 @@ describe('dts when bundle: false', () => {

expect(files.cjs).toMatchInlineSnapshot(`
[
"./dist/cjs/index.d.cts",
"./dist/cjs/sum.d.cts",
"./dist/cjs/utils/numbers.d.cts",
"./dist/cjs/utils/strings.d.cts",
"<ROOT>/e2e/cases/dts/bundle-false/auto-extension/dist/cjs/index.d.cts",
"<ROOT>/e2e/cases/dts/bundle-false/auto-extension/dist/cjs/sum.d.cts",
"<ROOT>/e2e/cases/dts/bundle-false/auto-extension/dist/cjs/utils/numbers.d.cts",
"<ROOT>/e2e/cases/dts/bundle-false/auto-extension/dist/cjs/utils/strings.d.cts",
]
`);
});
Expand All @@ -69,22 +69,26 @@ describe('dts when bundle: true', () => {
'dts',
);

expect(entryFiles.esm).toEqual('./dist/esm/main.d.ts');
expect(entryFiles.esm).toMatchInlineSnapshot(
`"<ROOT>/e2e/cases/dts/bundle/basic/dist/esm/main.d.ts"`,
);
expect(entries).toMatchSnapshot();
});

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

expect(entryFiles.esm).toEqual(undefined);
expect(entryFiles.esm).toMatchInlineSnapshot('undefined');
});

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

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

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

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

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

expect(entryFiles.esm).toEqual('./dist/esm/bundleName.d.ts');
expect(entryFiles.esm).toMatchInlineSnapshot(
`"<ROOT>/e2e/cases/dts/bundle/bundle-name/dist/esm/bundleName.d.ts"`,
);
});
});
7 changes: 4 additions & 3 deletions e2e/scripts/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import fg, {
} from 'fast-glob';
import fse from 'fs-extra';

export const getFiles = async (_pattern: string) => {};

// fast-glob only accepts posix path
// https://github.com/mrmlnc/fast-glob#convertpathtopatternpath
const convertPath = (path: string) => {
Expand All @@ -17,7 +15,10 @@ const convertPath = (path: string) => {
return path;
};

export const globContentJSON = async (path: string, options?: GlobOptions) => {
export const globContentJSON = async (
path: string,
options?: GlobOptions,
): Promise<Record<string, string>> => {
const files = await fg(convertPath(join(path, '**/*')), options);
const ret: Record<string, string> = {};

Expand Down
39 changes: 18 additions & 21 deletions e2e/scripts/shared.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { join } from 'node:path';
import { isAbsolute, join } from 'node:path';
import {
type InspectConfigResult,
mergeRsbuildConfig as mergeConfig,
Expand Down Expand Up @@ -39,11 +39,25 @@ export function generateBundleCjsConfig(
return mergeConfig(cjsBasicConfig, config)!;
}

type FormatType = 'esm' | 'cjs';
type FilePath = string;

type BuildResult = {
files: Record<FormatType, FilePath[]>;
contents: Record<FormatType, Record<FilePath, string>>;
entries: Record<FormatType, string>;
entryFiles: Record<FormatType, FilePath>;

rspackConfig: InspectConfigResult['origin']['bundlerConfigs'];
rsbuildConfig: InspectConfigResult['origin']['rsbuildConfig'];
isSuccess: boolean;
};

export async function getResults(
rslibConfig: RslibConfig,
fixturePath: string,
type: 'js' | 'dts',
) {
): Promise<Omit<BuildResult, 'rspackConfig' | 'rsbuildConfig' | 'isSuccess'>> {
const files: Record<string, string[]> = {};
const contents: Record<string, Record<string, string>> = {};
const entries: Record<string, string> = {};
Expand All @@ -62,18 +76,11 @@ export async function getResults(

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

const rawContent = await globContentJSON(globFolder, {
const content: Record<string, string> = await globContentJSON(globFolder, {
absolute: true,
ignore: ['/**/*.map'],
ignore: ['**/*.map'],
});

const content: Record<string, string> = {};

for (const key of Object.keys(rawContent)) {
const newKey = key.replace(fixturePath, '.');
content[newKey] = rawContent[key]!;
}

const fileSet = Object.keys(content).filter((file) => regex.test(file));
const filterContent: Record<string, string> = {};
for (const key of fileSet) {
Expand Down Expand Up @@ -102,16 +109,6 @@ export async function getResults(
};
}

type BuildResult = {
contents: Record<string, Record<string, string>>;
files: Record<string, string[]>;
entries: Record<string, string>;
entryFiles: Record<string, string>;
rspackConfig: InspectConfigResult['origin']['bundlerConfigs'];
rsbuildConfig: InspectConfigResult['origin']['rsbuildConfig'];
isSuccess: boolean;
};

export async function buildAndGetResults(
fixturePath: string,
type: 'all',
Expand Down
9 changes: 7 additions & 2 deletions packages/core/src/utils/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,12 @@ async function calcLongestCommonPath(
return null;
}

const splitPaths = absPaths.map((p) => p.split(path.sep));
// we support two cases
// 1. /packages-a/src/index.ts
// 2. D:/packages-a/src/index.ts
const sep = path.posix.sep as '/';

const splitPaths = absPaths.map((p) => p.split(sep));
let lcaFragments = splitPaths[0]!;
for (let i = 1; i < splitPaths.length; i++) {
const currentPath = splitPaths[i]!;
Expand All @@ -92,7 +97,7 @@ async function calcLongestCommonPath(
lcaFragments = lcaFragments.slice(0, j);
}

let lca = lcaFragments.length > 0 ? lcaFragments.join(path.sep) : '/';
let lca = lcaFragments.length > 0 ? lcaFragments.join(sep) : sep;

const stats = await fsP.stat(lca);
if (stats?.isFile()) {
Expand Down
20 changes: 10 additions & 10 deletions packages/core/tests/lcp.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ describe('LCP calculate correctly', () => {
expect(result).toEqual('/Users/Someone/project-a/src');
} else {
const result = await calcLongestCommonPath([
'D:\\Users\\Someone\\project-a\\src\\helpers',
'D:\\Users\\Someone\\project-a\\src',
'D:\\Users\\Someone\\project-a\\src\\utils',
'D:/Users/Someone/project-a/src/helpers',
'D:/Users/Someone/project-a/src',
'D:/Users/Someone/project-a/src/utils',
]);
expect(result).toEqual('D:\\Users\\Someone\\project-a\\src');
expect(result).toEqual('D:/Users/Someone/project-a/src');
}
});

Expand All @@ -49,11 +49,11 @@ describe('LCP calculate correctly', () => {
expect(result).toEqual('/Users/Someone/project-monorepo');
} else {
const result = await calcLongestCommonPath([
'D:\\Users\\Someone\\project-monorepo\\packages-a\\src\\index.ts',
'D:\\Users\\Someone\\project-monorepo\\packages-util\\src\\index.js',
'D:\\Users\\Someone\\project-monorepo\\script.js',
'D:/Users/Someone/project-monorepo/packages-a/src/index.ts',
'D:/Users/Someone/project-monorepo/packages-util/src/index.js',
'D:/Users/Someone/project-monorepo/script.js',
]);
expect(result).toEqual('D:\\Users\\Someone\\project-monorepo');
expect(result).toEqual('D:/Users/Someone/project-monorepo');
}
});

Expand All @@ -68,9 +68,9 @@ describe('LCP calculate correctly', () => {
expect(result).toEqual('/Users/Someone/project/src');
} else {
const result = await calcLongestCommonPath([
'D:\\Users\\Someone\\project\\src\\index.js',
'D:/Users/Someone/project/src/index.js',
]);
expect(result).toEqual('D:\\Users\\Someone\\project\\src');
expect(result).toEqual('D:/Users/Someone/project/src');
}
});
});
Loading

0 comments on commit 3244725

Please sign in to comment.