-
Notifications
You must be signed in to change notification settings - Fork 548
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: setup rolldown node test (#307)
- Loading branch information
Showing
8 changed files
with
402 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import type { RollupOptions } from '@rolldown/node' | ||
import path from 'path' | ||
|
||
const config: RollupOptions = { | ||
input: path.join(__dirname, 'main.js'), | ||
} | ||
|
||
export default config |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
console.log(1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import { describe, expect, test } from 'vitest' | ||
import { | ||
InputOptions, | ||
OutputOptions, | ||
RollupOptions, | ||
rolldown, | ||
} from '@rolldown/node' | ||
import path from 'path' | ||
import fs from 'fs' | ||
|
||
runCases() | ||
|
||
function runCases() { | ||
const testCasesRoot = path.join(__dirname, 'cases') | ||
const cases = fs.readdirSync(testCasesRoot) | ||
|
||
for (const name of cases) { | ||
describe(name, async () => { | ||
const subCasesRoot = path.join(testCasesRoot, name) | ||
const subCases = fs.readdirSync(subCasesRoot) | ||
|
||
for (const subCaseName of subCases) { | ||
const caseRoot = path.join(subCasesRoot, subCaseName) | ||
const config = await getCaseConfig(caseRoot) | ||
|
||
test(subCaseName, async () => { | ||
try { | ||
await runCaseBundle(caseRoot, config) | ||
expect(true) | ||
} catch (error) { | ||
throw error | ||
} | ||
}) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
async function runCaseBundle(caseRoot: string, config?: RollupOptions) { | ||
config = normalizedOptions(caseRoot, config) | ||
const build = await rolldown(config as InputOptions) | ||
await build.write(config.output as OutputOptions) | ||
} | ||
|
||
function normalizedOptions(caseRoot: string, config?: RollupOptions) { | ||
if (Array.isArray(config?.output)) { | ||
throw new Error(`The ${caseRoot} output shouldn't be array`) | ||
} | ||
const output = config?.output ?? {} | ||
|
||
return { | ||
input: config?.input ?? path.join(caseRoot, 'main.js'), | ||
output: { | ||
dir: output.dir ?? path.join(caseRoot, 'dist'), | ||
}, | ||
...config, | ||
} | ||
} | ||
|
||
async function getCaseConfig(caseRoot: string) { | ||
const caseConfigPath = path.join(caseRoot, 'config.ts') | ||
return fs.existsSync(caseConfigPath) | ||
? (await import(caseConfigPath)).default | ||
: undefined | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { defineConfig } from 'vitest/config' | ||
|
||
export default defineConfig({ | ||
test: { | ||
include: ['./test/runner.ts'], | ||
testTimeout: 20000, | ||
}, | ||
esbuild: { | ||
target: 'node18', | ||
}, | ||
}) |
Oops, something went wrong.