From ce859fb53d5041b05509d0e278197ba141411d09 Mon Sep 17 00:00:00 2001 From: Dunqing Date: Thu, 28 Mar 2024 20:44:48 +0800 Subject: [PATCH 1/5] chore: improve rolldown test based on import.meta.glob --- packages/rolldown/package.json | 3 +-- packages/rolldown/tests/fixture.test.ts | 30 +++++++++---------------- packages/rolldown/tsconfig.json | 4 +++- pnpm-lock.yaml | 3 --- 4 files changed, 14 insertions(+), 26 deletions(-) diff --git a/packages/rolldown/package.json b/packages/rolldown/package.json index daeedf1dd4..4aa8e6dd2a 100644 --- a/packages/rolldown/package.json +++ b/packages/rolldown/package.json @@ -80,8 +80,7 @@ "rollup": "^4.12.1", "type-fest": "^4.12.0", "unbuild": "^2.0.0", - "vitest": "^1.3.1", - "fast-glob": "^3.3.2" + "vitest": "^1.3.1" }, "optionalDependencies": { "@rolldown/binding-darwin-arm64": "workspace:*", diff --git a/packages/rolldown/tests/fixture.test.ts b/packages/rolldown/tests/fixture.test.ts index 9d70c8181b..bc26a21fcb 100644 --- a/packages/rolldown/tests/fixture.test.ts +++ b/packages/rolldown/tests/fixture.test.ts @@ -2,39 +2,29 @@ import { test } from 'vitest' import type { TestConfig } from './src/types' import { InputOptions, OutputOptions, rolldown } from 'rolldown' import nodePath from 'node:path' -import * as fastGlob from 'fast-glob' -import { loadTestConfig } from '@tests/utils' main() function main() { - const fixturesPath = nodePath.join(__dirname, 'fixtures') - const testConfigPaths = fastGlob.sync('fixtures/**/_config.ts', { - absolute: true, - cwd: __dirname, - }) - for (const testConfigPath of testConfigPaths) { - const dirPath = nodePath.relative( - fixturesPath, - nodePath.dirname(testConfigPath), - ) - test(dirPath, async (ctx) => { - const testConfig = await loadTestConfig(testConfigPath) - if (testConfig.skip) { - ctx.skip() - return - } + const testConfigPaths = import.meta.glob( + './fixtures/**/_config.ts', + { import: 'default', eager: true }, + ) + for (const [testConfigPath, testConfig] of Object.entries(testConfigPaths)) { + const dirPath = nodePath.dirname(testConfigPath) + const testName = dirPath.replace('./fixtures/', '') + test.skipIf(testConfig.skip)(testName, async () => { try { const output = await compileFixture( - nodePath.dirname(testConfigPath), + nodePath.join(import.meta.dirname, dirPath), testConfig, ) if (testConfig.afterTest) { testConfig.afterTest(output) } } catch (err) { - throw new Error(`Failed in ${testConfigPath}`, { cause: err }) + throw new Error(`Failed in ${testConfigPath}`) } }) } diff --git a/packages/rolldown/tsconfig.json b/packages/rolldown/tsconfig.json index dcbd411f1b..63d5bfeba3 100644 --- a/packages/rolldown/tsconfig.json +++ b/packages/rolldown/tsconfig.json @@ -42,7 +42,9 @@ } /* Specify a set of entries that re-map imports to additional lookup locations. */, // "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */ // "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */ - // "types": [], /* Specify type package names to be included without being referenced in a source file. */ + "types": [ + "vite/client" + ] /* Specify type package names to be included without being referenced in a source file. */, // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */ // "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */ // "allowImportingTsExtensions": true, /* Allow imports to include TypeScript file extensions. Requires '--moduleResolution bundler' and either '--noEmit' or '--emitDeclarationOnly' to be set. */ diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 4c730278c3..099190183f 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -133,9 +133,6 @@ importers: consola: specifier: ^3.2.3 version: 3.2.3 - fast-glob: - specifier: ^3.3.2 - version: 3.3.2 glob: specifier: ^10.3.10 version: 10.3.10 From cf6adfd049ecd724f830037ba551c664601318b2 Mon Sep 17 00:00:00 2001 From: Dunqing Date: Thu, 28 Mar 2024 20:52:53 +0800 Subject: [PATCH 2/5] fix: missing vite --- packages/rolldown/tests/fixture.test.ts | 2 ++ packages/rolldown/tsconfig.json | 4 +--- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/rolldown/tests/fixture.test.ts b/packages/rolldown/tests/fixture.test.ts index bc26a21fcb..5e64447af5 100644 --- a/packages/rolldown/tests/fixture.test.ts +++ b/packages/rolldown/tests/fixture.test.ts @@ -1,3 +1,5 @@ +/// + import { test } from 'vitest' import type { TestConfig } from './src/types' import { InputOptions, OutputOptions, rolldown } from 'rolldown' diff --git a/packages/rolldown/tsconfig.json b/packages/rolldown/tsconfig.json index 63d5bfeba3..6608278eec 100644 --- a/packages/rolldown/tsconfig.json +++ b/packages/rolldown/tsconfig.json @@ -42,9 +42,7 @@ } /* Specify a set of entries that re-map imports to additional lookup locations. */, // "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */ // "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */ - "types": [ - "vite/client" - ] /* Specify type package names to be included without being referenced in a source file. */, + "types": [] /* Specify type package names to be included without being referenced in a source file. */, // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */ // "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */ // "allowImportingTsExtensions": true, /* Allow imports to include TypeScript file extensions. Requires '--moduleResolution bundler' and either '--noEmit' or '--emitDeclarationOnly' to be set. */ From 2f171103d456de022a8a451ce5e75c0218984de7 Mon Sep 17 00:00:00 2001 From: Dunqing Date: Thu, 28 Mar 2024 20:55:03 +0800 Subject: [PATCH 3/5] fix: revert --- packages/rolldown/tests/fixture.test.ts | 2 +- packages/rolldown/tsconfig.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/rolldown/tests/fixture.test.ts b/packages/rolldown/tests/fixture.test.ts index 5e64447af5..1b2bd25b3e 100644 --- a/packages/rolldown/tests/fixture.test.ts +++ b/packages/rolldown/tests/fixture.test.ts @@ -26,7 +26,7 @@ function main() { testConfig.afterTest(output) } } catch (err) { - throw new Error(`Failed in ${testConfigPath}`) + throw new Error(`Failed in ${testConfigPath}`, { cause: err }) } }) } diff --git a/packages/rolldown/tsconfig.json b/packages/rolldown/tsconfig.json index 6608278eec..dcbd411f1b 100644 --- a/packages/rolldown/tsconfig.json +++ b/packages/rolldown/tsconfig.json @@ -42,7 +42,7 @@ } /* Specify a set of entries that re-map imports to additional lookup locations. */, // "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */ // "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */ - "types": [] /* Specify type package names to be included without being referenced in a source file. */, + // "types": [], /* Specify type package names to be included without being referenced in a source file. */ // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */ // "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */ // "allowImportingTsExtensions": true, /* Allow imports to include TypeScript file extensions. Requires '--moduleResolution bundler' and either '--noEmit' or '--emitDeclarationOnly' to be set. */ From aca8cecd34feca018d0d91dca231dd63834e497f Mon Sep 17 00:00:00 2001 From: Dunqing Date: Thu, 28 Mar 2024 21:04:08 +0800 Subject: [PATCH 4/5] fix: missing vite/client --- packages/rolldown/package.json | 1 + packages/rolldown/tests/fixture.test.ts | 2 -- packages/rolldown/tsconfig.json | 4 +++- pnpm-lock.yaml | 3 +++ 4 files changed, 7 insertions(+), 3 deletions(-) diff --git a/packages/rolldown/package.json b/packages/rolldown/package.json index 4aa8e6dd2a..527b3343dc 100644 --- a/packages/rolldown/package.json +++ b/packages/rolldown/package.json @@ -80,6 +80,7 @@ "rollup": "^4.12.1", "type-fest": "^4.12.0", "unbuild": "^2.0.0", + "vite": "^5.1.5", "vitest": "^1.3.1" }, "optionalDependencies": { diff --git a/packages/rolldown/tests/fixture.test.ts b/packages/rolldown/tests/fixture.test.ts index 1b2bd25b3e..589fa8aefe 100644 --- a/packages/rolldown/tests/fixture.test.ts +++ b/packages/rolldown/tests/fixture.test.ts @@ -1,5 +1,3 @@ -/// - import { test } from 'vitest' import type { TestConfig } from './src/types' import { InputOptions, OutputOptions, rolldown } from 'rolldown' diff --git a/packages/rolldown/tsconfig.json b/packages/rolldown/tsconfig.json index dcbd411f1b..63d5bfeba3 100644 --- a/packages/rolldown/tsconfig.json +++ b/packages/rolldown/tsconfig.json @@ -42,7 +42,9 @@ } /* Specify a set of entries that re-map imports to additional lookup locations. */, // "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */ // "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */ - // "types": [], /* Specify type package names to be included without being referenced in a source file. */ + "types": [ + "vite/client" + ] /* Specify type package names to be included without being referenced in a source file. */, // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */ // "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */ // "allowImportingTsExtensions": true, /* Allow imports to include TypeScript file extensions. Requires '--moduleResolution bundler' and either '--noEmit' or '--emitDeclarationOnly' to be set. */ diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 099190183f..769c5d3d44 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -148,6 +148,9 @@ importers: unbuild: specifier: ^2.0.0 version: 2.0.0(typescript@5.4.3) + vite: + specifier: ^5.1.5 + version: 5.1.6(@types/node@20.11.26) vitest: specifier: ^1.3.1 version: 1.3.1(@types/node@20.11.26) From ee97a5f93e77f055f3d396749c6b50e79b7a86aa Mon Sep 17 00:00:00 2001 From: Dunqing Date: Thu, 28 Mar 2024 22:04:03 +0800 Subject: [PATCH 5/5] fix: build failed --- packages/rolldown/tsconfig.json | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/rolldown/tsconfig.json b/packages/rolldown/tsconfig.json index 63d5bfeba3..4c61ddc319 100644 --- a/packages/rolldown/tsconfig.json +++ b/packages/rolldown/tsconfig.json @@ -43,6 +43,7 @@ // "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */ // "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */ "types": [ + "node", "vite/client" ] /* Specify type package names to be included without being referenced in a source file. */, // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */