Skip to content

Commit

Permalink
chore(test): pre-import test config files byimport.meta.glob (#685)
Browse files Browse the repository at this point in the history
  • Loading branch information
Dunqing committed Mar 28, 2024
1 parent 0729dfb commit 31926bd
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 25 deletions.
4 changes: 2 additions & 2 deletions packages/rolldown/package.json
Expand Up @@ -80,8 +80,8 @@
"rollup": "^4.12.1",
"type-fest": "^4.12.0",
"unbuild": "^2.0.0",
"vitest": "^1.3.1",
"fast-glob": "^3.3.2"
"vite": "^5.1.5",
"vitest": "^1.3.1"
},
"optionalDependencies": {
"@rolldown/binding-darwin-arm64": "workspace:*",
Expand Down
28 changes: 9 additions & 19 deletions packages/rolldown/tests/fixture.test.ts
Expand Up @@ -2,32 +2,22 @@ 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<TestConfig>(
'./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) {
Expand Down
5 changes: 4 additions & 1 deletion packages/rolldown/tsconfig.json
Expand Up @@ -42,7 +42,10 @@
} /* 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": [
"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. */
// "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. */
Expand Down
6 changes: 3 additions & 3 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 31926bd

Please sign in to comment.