Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(test): pre-import test config files byimport.meta.glob #685

Merged
merged 5 commits into from Mar 28, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 1 addition & 2 deletions packages/rolldown/package.json
Expand Up @@ -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:*",
Expand Down
30 changes: 11 additions & 19 deletions packages/rolldown/tests/fixture.test.ts
@@ -1,33 +1,25 @@
/// <reference types="vite/client" />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feel this not ideal. Maybe vitest could exposed these from https://github.com/vitest-dev/vitest/blob/main/packages/vitest/importMeta.d.ts.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I will report this issue to vitest


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
3 changes: 0 additions & 3 deletions pnpm-lock.yaml

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