From 8045d398009e6d392628c4dd0eed12be323bf4a0 Mon Sep 17 00:00:00 2001 From: SoonIter Date: Mon, 12 Aug 2024 17:28:14 +0800 Subject: [PATCH] ci: update the snapshot --- e2e/cases/bundle-false/index.test.ts | 20 ++++----- .../dts/__snapshots__/index.test.ts.snap | 10 ++--- e2e/cases/dts/index.test.ts | 44 +++++++++++-------- e2e/scripts/shared.ts | 38 ++++++++-------- 4 files changed, 59 insertions(+), 53 deletions(-) diff --git a/e2e/cases/bundle-false/index.test.ts b/e2e/cases/bundle-false/index.test.ts index d08751dd6..48fb66de6 100644 --- a/e2e/cases/bundle-false/index.test.ts +++ b/e2e/cases/bundle-false/index.test.ts @@ -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", + "/e2e/cases/bundle-false/basic/dist/esm/index.js", + "/e2e/cases/bundle-false/basic/dist/esm/sum.js", + "/e2e/cases/bundle-false/basic/dist/esm/utils/numbers.js", + "/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", + "/e2e/cases/bundle-false/basic/dist/cjs/index.js", + "/e2e/cases/bundle-false/basic/dist/cjs/sum.js", + "/e2e/cases/bundle-false/basic/dist/cjs/utils/numbers.js", + "/e2e/cases/bundle-false/basic/dist/cjs/utils/strings.js", ] `); }); @@ -30,12 +30,12 @@ test('single file', async () => { expect(files.esm).toMatchInlineSnapshot(` [ - "./dist/esm/index.js", + "/e2e/cases/bundle-false/single-file/dist/esm/index.js", ] `); expect(files.cjs).toMatchInlineSnapshot(` [ - "./dist/cjs/index.js", + "/e2e/cases/bundle-false/single-file/dist/cjs/index.js", ] `); }); diff --git a/e2e/cases/dts/__snapshots__/index.test.ts.snap b/e2e/cases/dts/__snapshots__/index.test.ts.snap index 4bce88be6..353e92c91 100644 --- a/e2e/cases/dts/__snapshots__/index.test.ts.snap +++ b/e2e/cases/dts/__snapshots__/index.test.ts.snap @@ -2,25 +2,25 @@ exports[`dts when bundle: false > basic 2`] = ` { - "./dist/esm/index.d.ts": "export * from './utils/numbers'; + "/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; + "/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; + "/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"; + "/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; diff --git a/e2e/cases/dts/index.test.ts b/e2e/cases/dts/index.test.ts index 979218c5a..bd16c95dc 100644 --- a/e2e/cases/dts/index.test.ts +++ b/e2e/cases/dts/index.test.ts @@ -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", + "/e2e/cases/dts/bundle-false/basic/dist/esm/index.d.ts", + "/e2e/cases/dts/bundle-false/basic/dist/esm/sum.d.ts", + "/e2e/cases/dts/bundle-false/basic/dist/esm/utils/numbers.d.ts", + "/e2e/cases/dts/bundle-false/basic/dist/esm/utils/strings.d.ts", ] `); expect(contents.esm).toMatchSnapshot(); @@ -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 () => { @@ -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", + "/e2e/cases/dts/bundle-false/dist-path/dist/custom/index.d.ts", + "/e2e/cases/dts/bundle-false/dist-path/dist/custom/sum.d.ts", + "/e2e/cases/dts/bundle-false/dist-path/dist/custom/utils/numbers.d.ts", + "/e2e/cases/dts/bundle-false/dist-path/dist/custom/utils/strings.d.ts", ] `); }); @@ -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", + "/e2e/cases/dts/bundle-false/auto-extension/dist/cjs/index.d.cts", + "/e2e/cases/dts/bundle-false/auto-extension/dist/cjs/sum.d.cts", + "/e2e/cases/dts/bundle-false/auto-extension/dist/cjs/utils/numbers.d.cts", + "/e2e/cases/dts/bundle-false/auto-extension/dist/cjs/utils/strings.d.cts", ] `); }); @@ -69,7 +69,9 @@ describe('dts when bundle: true', () => { 'dts', ); - expect(entryFiles.esm).toEqual('./dist/esm/main.d.ts'); + expect(entryFiles.esm).toMatchInlineSnapshot( + `"/e2e/cases/dts/bundle/basic/dist/esm/main.d.ts"`, + ); expect(entries).toMatchSnapshot(); }); @@ -77,14 +79,16 @@ describe('dts when bundle: true', () => { 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( + `"/e2e/cases/dts/bundle/dist-path/dist/custom/main.d.ts"`, + ); }); test('abortOnError: false', async () => { @@ -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( + `"/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( + `"/e2e/cases/dts/bundle/bundle-name/dist/esm/bundleName.d.ts"`, + ); }); }); diff --git a/e2e/scripts/shared.ts b/e2e/scripts/shared.ts index c0a53503e..760c3d2d7 100644 --- a/e2e/scripts/shared.ts +++ b/e2e/scripts/shared.ts @@ -39,11 +39,25 @@ export function generateBundleCjsConfig( return mergeConfig(cjsBasicConfig, config)!; } +type FormatType = 'esm' | 'cjs'; +type FilePath = string; + +type BuildResult = { + files: Record; + contents: Record>; + entries: Record; + entryFiles: Record; + + rspackConfig: InspectConfigResult['origin']['bundlerConfigs']; + rsbuildConfig: InspectConfigResult['origin']['rsbuildConfig']; + isSuccess: boolean; +}; + export async function getResults( rslibConfig: RslibConfig, fixturePath: string, type: 'js' | 'dts', -) { +): Promise> { const files: Record = {}; const contents: Record> = {}; const entries: Record = {}; @@ -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 = await globContentJSON(globFolder, { absolute: true, - ignore: ['/**/*.map'], + cwd: fixturePath, + ignore: ['**/*.map'], }); - const content: Record = {}; - - 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 = {}; for (const key of fileSet) { @@ -102,16 +110,6 @@ export async function getResults( }; } -type BuildResult = { - contents: Record>; - files: Record; - entries: Record; - entryFiles: Record; - rspackConfig: InspectConfigResult['origin']['bundlerConfigs']; - rsbuildConfig: InspectConfigResult['origin']['rsbuildConfig']; - isSuccess: boolean; -}; - export async function buildAndGetResults( fixturePath: string, type: 'all',