From 6ee69df2dd6a4c7da99f6b3368d71dfacecbf30b Mon Sep 17 00:00:00 2001 From: Soon Date: Mon, 5 Aug 2024 19:45:45 +0800 Subject: [PATCH] chore(infra/e2e): @e2e/helper rather than #imports (#59) --- e2e/cases/alias/index.test.ts | 2 +- e2e/cases/alias/rslib.config.ts | 2 +- e2e/cases/autoExtension/index.test.ts | 2 +- e2e/cases/autoExtension/type-commonjs/rslib.config.ts | 5 +---- e2e/cases/autoExtension/type-module/rslib.config.ts | 5 +---- e2e/cases/bundle-false/basic/rslib.config.ts | 2 +- e2e/cases/bundle-false/index.test.ts | 2 +- e2e/cases/cli/index.test.ts | 2 +- e2e/cases/cli/rslib.config.ts | 2 +- e2e/cases/define/index.test.ts | 2 +- e2e/cases/define/rslib.config.ts | 2 +- e2e/cases/dts/bundle-false/rslib.config.ts | 2 +- e2e/cases/dts/index.test.ts | 2 +- e2e/cases/externals/browser/index.test.ts | 2 +- e2e/cases/externals/browser/rslib.config.ts | 2 +- e2e/cases/externals/node/index.test.ts | 2 +- e2e/cases/externals/node/rslib.config.ts | 2 +- e2e/cases/syntax/config/index.test.ts | 2 +- e2e/cases/syntax/config/rslib.config.ts | 2 +- e2e/cases/syntax/default/index.test.ts | 2 +- e2e/cases/syntax/default/rslib.config.ts | 2 +- e2e/package.json | 5 +---- e2e/scripts/helper.ts | 2 +- e2e/scripts/index.ts | 2 ++ e2e/scripts/main.ts | 1 - e2e/scripts/package.json | 7 +++++++ e2e/scripts/shared.ts | 8 ++------ pnpm-lock.yaml | 5 +++++ 28 files changed, 39 insertions(+), 39 deletions(-) create mode 100644 e2e/scripts/index.ts delete mode 100644 e2e/scripts/main.ts create mode 100644 e2e/scripts/package.json diff --git a/e2e/cases/alias/index.test.ts b/e2e/cases/alias/index.test.ts index 8fce62eb2..990037263 100644 --- a/e2e/cases/alias/index.test.ts +++ b/e2e/cases/alias/index.test.ts @@ -1,5 +1,5 @@ +import { buildAndGetResults } from '@e2e/helper'; import { expect, test } from 'vitest'; -import { buildAndGetResults } from '#shared'; test('source.alias', async () => { const fixturePath = __dirname; diff --git a/e2e/cases/alias/rslib.config.ts b/e2e/cases/alias/rslib.config.ts index e713354f4..075d2e541 100644 --- a/e2e/cases/alias/rslib.config.ts +++ b/e2e/cases/alias/rslib.config.ts @@ -1,5 +1,5 @@ +import { generateBundleCjsConfig, generateBundleEsmConfig } from '@e2e/helper'; import { defineConfig } from '@rslib/core'; -import { generateBundleCjsConfig, generateBundleEsmConfig } from '#shared'; export default defineConfig({ lib: [generateBundleEsmConfig(__dirname), generateBundleCjsConfig(__dirname)], diff --git a/e2e/cases/autoExtension/index.test.ts b/e2e/cases/autoExtension/index.test.ts index 7698a3dce..be4c40e89 100644 --- a/e2e/cases/autoExtension/index.test.ts +++ b/e2e/cases/autoExtension/index.test.ts @@ -1,6 +1,6 @@ import { extname, join } from 'node:path'; +import { buildAndGetResults } from '@e2e/helper'; import { expect, test } from 'vitest'; -import { buildAndGetResults } from '#shared'; test('autoExtension generate .mjs in build artifacts with esm format when type is commonjs', async () => { const fixturePath = join(__dirname, 'type-commonjs'); diff --git a/e2e/cases/autoExtension/type-commonjs/rslib.config.ts b/e2e/cases/autoExtension/type-commonjs/rslib.config.ts index 0e80fc212..da1474db4 100644 --- a/e2e/cases/autoExtension/type-commonjs/rslib.config.ts +++ b/e2e/cases/autoExtension/type-commonjs/rslib.config.ts @@ -1,8 +1,5 @@ +import { generateBundleCjsConfig, generateBundleEsmConfig } from '@e2e/helper'; import { defineConfig } from '@rslib/core'; -import { - generateBundleCjsConfig, - generateBundleEsmConfig, -} from '../../../scripts/shared'; export default defineConfig({ lib: [ diff --git a/e2e/cases/autoExtension/type-module/rslib.config.ts b/e2e/cases/autoExtension/type-module/rslib.config.ts index 0e80fc212..da1474db4 100644 --- a/e2e/cases/autoExtension/type-module/rslib.config.ts +++ b/e2e/cases/autoExtension/type-module/rslib.config.ts @@ -1,8 +1,5 @@ +import { generateBundleCjsConfig, generateBundleEsmConfig } from '@e2e/helper'; import { defineConfig } from '@rslib/core'; -import { - generateBundleCjsConfig, - generateBundleEsmConfig, -} from '../../../scripts/shared'; export default defineConfig({ lib: [ diff --git a/e2e/cases/bundle-false/basic/rslib.config.ts b/e2e/cases/bundle-false/basic/rslib.config.ts index df465227e..c5d9857f1 100644 --- a/e2e/cases/bundle-false/basic/rslib.config.ts +++ b/e2e/cases/bundle-false/basic/rslib.config.ts @@ -1,5 +1,5 @@ +import { generateBundleCjsConfig, generateBundleEsmConfig } from '@e2e/helper'; import { defineConfig } from '@rslib/core'; -import { generateBundleCjsConfig, generateBundleEsmConfig } from '#shared'; export default defineConfig({ lib: [ diff --git a/e2e/cases/bundle-false/index.test.ts b/e2e/cases/bundle-false/index.test.ts index 556750a8f..6beb2824e 100644 --- a/e2e/cases/bundle-false/index.test.ts +++ b/e2e/cases/bundle-false/index.test.ts @@ -1,6 +1,6 @@ import { join } from 'node:path'; +import { buildAndGetResults } from '@e2e/helper'; import { expect, test } from 'vitest'; -import { buildAndGetResults } from '#shared'; test('bundle: false', async () => { const fixturePath = join(__dirname, 'basic'); diff --git a/e2e/cases/cli/index.test.ts b/e2e/cases/cli/index.test.ts index 3282bd6ae..dd1d70557 100644 --- a/e2e/cases/cli/index.test.ts +++ b/e2e/cases/cli/index.test.ts @@ -1,8 +1,8 @@ import { execSync } from 'node:child_process'; import path from 'node:path'; +import { globContentJSON } from '@e2e/helper'; import fse from 'fs-extra'; import { expect, test } from 'vitest'; -import { globContentJSON } from '#helper'; test.todo('build command', async () => {}); diff --git a/e2e/cases/cli/rslib.config.ts b/e2e/cases/cli/rslib.config.ts index 7c1a0f2a9..78f3d6304 100644 --- a/e2e/cases/cli/rslib.config.ts +++ b/e2e/cases/cli/rslib.config.ts @@ -1,5 +1,5 @@ +import { generateBundleEsmConfig } from '@e2e/helper'; import { defineConfig } from '@rslib/core'; -import { generateBundleEsmConfig } from '#shared'; export default defineConfig({ lib: [generateBundleEsmConfig(__dirname)], diff --git a/e2e/cases/define/index.test.ts b/e2e/cases/define/index.test.ts index 6b01111f6..5aeb092ae 100644 --- a/e2e/cases/define/index.test.ts +++ b/e2e/cases/define/index.test.ts @@ -1,5 +1,5 @@ +import { buildAndGetResults } from '@e2e/helper'; import { expect, test } from 'vitest'; -import { buildAndGetResults } from '#shared'; test('source.define', async () => { const fixturePath = __dirname; diff --git a/e2e/cases/define/rslib.config.ts b/e2e/cases/define/rslib.config.ts index ce3ac2601..bbd244727 100644 --- a/e2e/cases/define/rslib.config.ts +++ b/e2e/cases/define/rslib.config.ts @@ -1,5 +1,5 @@ +import { generateBundleCjsConfig, generateBundleEsmConfig } from '@e2e/helper'; import { defineConfig } from '@rslib/core'; -import { generateBundleCjsConfig, generateBundleEsmConfig } from '#shared'; export default defineConfig({ lib: [generateBundleEsmConfig(__dirname), generateBundleCjsConfig(__dirname)], diff --git a/e2e/cases/dts/bundle-false/rslib.config.ts b/e2e/cases/dts/bundle-false/rslib.config.ts index 6126019a2..0dc33ac98 100644 --- a/e2e/cases/dts/bundle-false/rslib.config.ts +++ b/e2e/cases/dts/bundle-false/rslib.config.ts @@ -1,5 +1,5 @@ +import { generateBundleCjsConfig, generateBundleEsmConfig } from '@e2e/helper'; import { defineConfig } from '@rslib/core'; -import { generateBundleCjsConfig, generateBundleEsmConfig } from '#shared'; export default defineConfig({ lib: [ diff --git a/e2e/cases/dts/index.test.ts b/e2e/cases/dts/index.test.ts index 918459c67..22e5f307b 100644 --- a/e2e/cases/dts/index.test.ts +++ b/e2e/cases/dts/index.test.ts @@ -1,6 +1,6 @@ import { join } from 'node:path'; +import { buildAndGetResults } from '@e2e/helper'; import { expect, test } from 'vitest'; -import { buildAndGetResults } from '#shared'; test('dts when bundle: false', async () => { const fixturePath = join(__dirname, 'bundle-false'); diff --git a/e2e/cases/externals/browser/index.test.ts b/e2e/cases/externals/browser/index.test.ts index c9c747d48..87f80ab5a 100644 --- a/e2e/cases/externals/browser/index.test.ts +++ b/e2e/cases/externals/browser/index.test.ts @@ -1,6 +1,6 @@ import { join } from 'node:path'; +import { buildAndGetResults } from '@e2e/helper'; import { expect, test } from 'vitest'; -import { buildAndGetResults } from '#shared'; test('should fail to build when `output.target` is not "node"', async () => { const fixturePath = join(__dirname); diff --git a/e2e/cases/externals/browser/rslib.config.ts b/e2e/cases/externals/browser/rslib.config.ts index 0ccda950d..b110dc60b 100644 --- a/e2e/cases/externals/browser/rslib.config.ts +++ b/e2e/cases/externals/browser/rslib.config.ts @@ -1,5 +1,5 @@ +import { generateBundleCjsConfig, generateBundleEsmConfig } from '@e2e/helper'; import { defineConfig } from '@rslib/core'; -import { generateBundleCjsConfig, generateBundleEsmConfig } from '#shared'; export default defineConfig({ lib: [generateBundleEsmConfig(__dirname), generateBundleCjsConfig(__dirname)], diff --git a/e2e/cases/externals/node/index.test.ts b/e2e/cases/externals/node/index.test.ts index 3aff75de1..8e15fdce2 100644 --- a/e2e/cases/externals/node/index.test.ts +++ b/e2e/cases/externals/node/index.test.ts @@ -1,6 +1,6 @@ import { join } from 'node:path'; +import { buildAndGetResults } from '@e2e/helper'; import { expect, test } from 'vitest'; -import { buildAndGetResults } from '#shared'; test('auto externalize Node.js built-in modules when `output.target` is "node"', async () => { const fixturePath = join(__dirname); diff --git a/e2e/cases/externals/node/rslib.config.ts b/e2e/cases/externals/node/rslib.config.ts index 8025fca16..ec7be0242 100644 --- a/e2e/cases/externals/node/rslib.config.ts +++ b/e2e/cases/externals/node/rslib.config.ts @@ -1,5 +1,5 @@ +import { generateBundleCjsConfig, generateBundleEsmConfig } from '@e2e/helper'; import { defineConfig } from '@rslib/core'; -import { generateBundleCjsConfig, generateBundleEsmConfig } from '#shared'; export default defineConfig({ lib: [ diff --git a/e2e/cases/syntax/config/index.test.ts b/e2e/cases/syntax/config/index.test.ts index 856371f1c..3f023169e 100644 --- a/e2e/cases/syntax/config/index.test.ts +++ b/e2e/cases/syntax/config/index.test.ts @@ -1,5 +1,5 @@ +import { buildAndGetResults } from '@e2e/helper'; import { expect, test } from 'vitest'; -import { buildAndGetResults } from '#shared'; test('should downgrade class private method by default', async () => { const fixturePath = __dirname; diff --git a/e2e/cases/syntax/config/rslib.config.ts b/e2e/cases/syntax/config/rslib.config.ts index 6ce0a9bcc..bb42798e4 100644 --- a/e2e/cases/syntax/config/rslib.config.ts +++ b/e2e/cases/syntax/config/rslib.config.ts @@ -1,5 +1,5 @@ +import { generateBundleCjsConfig, generateBundleEsmConfig } from '@e2e/helper'; import { defineConfig } from '@rslib/core'; -import { generateBundleCjsConfig, generateBundleEsmConfig } from '#shared'; export default defineConfig({ lib: [ diff --git a/e2e/cases/syntax/default/index.test.ts b/e2e/cases/syntax/default/index.test.ts index 7aa5f6612..71ec97dbf 100644 --- a/e2e/cases/syntax/default/index.test.ts +++ b/e2e/cases/syntax/default/index.test.ts @@ -1,5 +1,5 @@ +import { buildAndGetResults } from '@e2e/helper'; import { expect, test } from 'vitest'; -import { buildAndGetResults } from '#shared'; test('should downgrade class private method by default', async () => { const fixturePath = __dirname; diff --git a/e2e/cases/syntax/default/rslib.config.ts b/e2e/cases/syntax/default/rslib.config.ts index db7071fce..03252f356 100644 --- a/e2e/cases/syntax/default/rslib.config.ts +++ b/e2e/cases/syntax/default/rslib.config.ts @@ -1,5 +1,5 @@ +import { generateBundleCjsConfig, generateBundleEsmConfig } from '@e2e/helper'; import { defineConfig } from '@rslib/core'; -import { generateBundleCjsConfig, generateBundleEsmConfig } from '#shared'; export default defineConfig({ lib: [generateBundleEsmConfig(__dirname), generateBundleCjsConfig(__dirname)], diff --git a/e2e/package.json b/e2e/package.json index 4c687e7fd..90c2e2032 100644 --- a/e2e/package.json +++ b/e2e/package.json @@ -2,10 +2,6 @@ "name": "@rslib/e2e", "private": true, "type": "module", - "imports": { - "#helper": "./scripts/helper.ts", - "#shared": "./scripts/shared.ts" - }, "scripts": { "test": "playwright test --pass-with-no-tests" }, @@ -13,6 +9,7 @@ "react": "^18.3.1" }, "devDependencies": { + "@e2e/helper": "workspace:*", "@playwright/test": "1.43.1", "@rsbuild/core": "1.0.1-beta.8", "@rslib/core": "workspace:*", diff --git a/e2e/scripts/helper.ts b/e2e/scripts/helper.ts index aa3090f52..9b16b7fc9 100644 --- a/e2e/scripts/helper.ts +++ b/e2e/scripts/helper.ts @@ -6,7 +6,7 @@ import fg, { } from 'fast-glob'; import fse from 'fs-extra'; -export const getFiles = async (pattern: string) => {}; +export const getFiles = async (_pattern: string) => {}; // fast-glob only accepts posix path // https://github.com/mrmlnc/fast-glob#convertpathtopatternpath diff --git a/e2e/scripts/index.ts b/e2e/scripts/index.ts new file mode 100644 index 000000000..68c9a9a09 --- /dev/null +++ b/e2e/scripts/index.ts @@ -0,0 +1,2 @@ +export * from './helper'; +export * from './shared'; diff --git a/e2e/scripts/main.ts b/e2e/scripts/main.ts deleted file mode 100644 index de0d5d882..000000000 --- a/e2e/scripts/main.ts +++ /dev/null @@ -1 +0,0 @@ -import {} from '@rslib/core'; diff --git a/e2e/scripts/package.json b/e2e/scripts/package.json new file mode 100644 index 000000000..9b3407516 --- /dev/null +++ b/e2e/scripts/package.json @@ -0,0 +1,7 @@ +{ + "name": "@e2e/helper", + "version": "1.0.0", + "private": true, + "main": "index.ts", + "types": "index.ts" +} diff --git a/e2e/scripts/shared.ts b/e2e/scripts/shared.ts index bfeb0fb87..a67475319 100644 --- a/e2e/scripts/shared.ts +++ b/e2e/scripts/shared.ts @@ -1,16 +1,12 @@ import { join } from 'node:path'; import { type InspectConfigResult, - type Rspack, mergeRsbuildConfig as mergeConfig, } from '@rsbuild/core'; import type { LibConfig, RslibConfig } from '@rslib/core'; -import { globContentJSON } from '#helper'; import { build } from '../../packages/core/src/build'; -import { - composeCreateRsbuildConfig, - loadConfig, -} from '../../packages/core/src/config'; +import { loadConfig } from '../../packages/core/src/config'; +import { globContentJSON } from './helper'; export function generateBundleEsmConfig( cwd: string, diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index d6886cf59..d87e80650 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -63,6 +63,9 @@ importers: specifier: ^18.3.1 version: 18.3.1 devDependencies: + '@e2e/helper': + specifier: workspace:* + version: link:scripts '@playwright/test': specifier: 1.43.1 version: 1.43.1 @@ -97,6 +100,8 @@ importers: e2e/cases/dts/bundle: {} + e2e/scripts: {} + examples/express-plugin: devDependencies: '@rslib/core':