Skip to content

Commit

Permalink
ci: update the snapshot
Browse files Browse the repository at this point in the history
  • Loading branch information
SoonIter committed Aug 12, 2024
1 parent 9d40d43 commit 8045d39
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 53 deletions.
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(`

Check failure on line 9 in e2e/cases/bundle-false/index.test.ts

View workflow job for this annotation

GitHub Actions / e2e-windows (18.x)

cases/bundle-false/index.test.ts > basic

Error: Snapshot `basic 1` mismatched - Expected + Received [ - "<ROOT>/e2e/cases/bundle-false/basic/dist/esm/index.js", + "<ROOT>/e2e/cases/bundle-false/basic/dist/esm/a/rslib/rslib/e2e/cases/bundle-false/basic/src/index.js", - "<ROOT>/e2e/cases/bundle-false/basic/dist/esm/sum.js", + "<ROOT>/e2e/cases/bundle-false/basic/dist/esm/a/rslib/rslib/e2e/cases/bundle-false/basic/src/sum.js", - "<ROOT>/e2e/cases/bundle-false/basic/dist/esm/utils/numbers.js", + "<ROOT>/e2e/cases/bundle-false/basic/dist/esm/a/rslib/rslib/e2e/cases/bundle-false/basic/src/utils/numbers.js", - "<ROOT>/e2e/cases/bundle-false/basic/dist/esm/utils/strings.js", + "<ROOT>/e2e/cases/bundle-false/basic/dist/esm/a/rslib/rslib/e2e/cases/bundle-false/basic/src/utils/strings.js", ] ❯ cases/bundle-false/index.test.ts:9:21
[
"./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(`

Check failure on line 53 in e2e/cases/dts/index.test.ts

View workflow job for this annotation

GitHub Actions / e2e-windows (18.x)

cases/dts/index.test.ts > dts when bundle: false > autoExtension: true

Error: Snapshot `dts when bundle: false > autoExtension: true 1` mismatched - Expected + Received [ - "<ROOT>/e2e/cases/dts/bundle-false/auto-extension/dist/cjs/index.d.cts", + "<ROOT>/e2e/cases/dts/bundle-false/auto-extension/dist/cjs/index.d.ts", - "<ROOT>/e2e/cases/dts/bundle-false/auto-extension/dist/cjs/sum.d.cts", + "<ROOT>/e2e/cases/dts/bundle-false/auto-extension/dist/cjs/sum.d.ts", - "<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/numbers.d.ts", - "<ROOT>/e2e/cases/dts/bundle-false/auto-extension/dist/cjs/utils/strings.d.cts", + "<ROOT>/e2e/cases/dts/bundle-false/auto-extension/dist/cjs/utils/strings.d.ts", ] ❯ cases/dts/index.test.ts:53:23
[
"./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"`,
);
});
});
38 changes: 18 additions & 20 deletions e2e/scripts/shared.ts
Original file line number Diff line number Diff line change
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,12 @@ 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'],
cwd: fixturePath,
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 +110,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

0 comments on commit 8045d39

Please sign in to comment.