-
Notifications
You must be signed in to change notification settings - Fork 97
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
[Suggestion] Add test scaffolding #502
Open
drwpow
wants to merge
1
commit into
unjs:main
Choose a base branch
from
drwpow:tests
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html | ||
|
||
exports[`Build fixtures > declaration (mkdist) > a.d.ts 1`] = ` | ||
"export declare function foo(): number; | ||
" | ||
`; | ||
|
||
exports[`Build fixtures > declaration (mkdist) > a.mjs 1`] = ` | ||
"export function foo() { | ||
return 42; | ||
} | ||
" | ||
`; | ||
|
||
exports[`Build fixtures > declaration (mkdist) > index.d.ts 1`] = ` | ||
"export { foo } from "./a.js"; | ||
" | ||
`; | ||
|
||
exports[`Build fixtures > declaration (mkdist) > index.mjs 1`] = ` | ||
"export { foo } from "./a.js"; | ||
" | ||
`; | ||
|
||
exports[`Build fixtures > declaration (rollup) > index.cjs 1`] = ` | ||
"'use strict'; | ||
|
||
function foo() { | ||
return 42; | ||
} | ||
|
||
exports.foo = foo; | ||
" | ||
`; | ||
|
||
exports[`Build fixtures > declaration (rollup) > index.d.cts 1`] = ` | ||
"declare function foo(): number; | ||
|
||
export { foo }; | ||
" | ||
`; | ||
|
||
exports[`Build fixtures > declaration (rollup) > index.d.mts 1`] = ` | ||
"declare function foo(): number; | ||
|
||
export { foo }; | ||
" | ||
`; | ||
|
||
exports[`Build fixtures > declaration (rollup) > index.d.ts 1`] = ` | ||
"declare function foo(): number; | ||
|
||
export { foo }; | ||
" | ||
`; | ||
|
||
exports[`Build fixtures > declaration (rollup) > index.mjs 1`] = ` | ||
"function foo() { | ||
return 42; | ||
} | ||
|
||
export { foo }; | ||
" | ||
`; | ||
|
||
exports[`Build fixtures > sourcemap (mkdist) > a.mjs 1`] = ` | ||
"export function foo() { | ||
return 42; | ||
} | ||
" | ||
`; | ||
|
||
exports[`Build fixtures > sourcemap (mkdist) > index.mjs 1`] = ` | ||
"export { foo } from "./a.js"; | ||
" | ||
`; | ||
|
||
exports[`Build fixtures > sourcemap (rollup) > index.cjs 1`] = ` | ||
"'use strict'; | ||
|
||
function foo() { | ||
return 42; | ||
} | ||
|
||
exports.foo = foo; | ||
//# sourceMappingURL=index.cjs.map | ||
" | ||
`; | ||
|
||
exports[`Build fixtures > sourcemap (rollup) > index.cjs.map 1`] = `"{"version":3,"file":"index.cjs","sources":["../src/a.ts"],"sourcesContent":["export function foo(): number {\\n return 42;\\n}\\n"],"names":[],"mappings":";;AAAO,SAAS,GAAc,GAAA;AAC5B,EAAO,OAAA,EAAA;AACT;;;;"}"`; | ||
|
||
exports[`Build fixtures > sourcemap (rollup) > index.mjs 1`] = ` | ||
"function foo() { | ||
return 42; | ||
} | ||
|
||
export { foo }; | ||
//# sourceMappingURL=index.mjs.map | ||
" | ||
`; | ||
|
||
exports[`Build fixtures > sourcemap (rollup) > index.mjs.map 1`] = `"{"version":3,"file":"index.mjs","sources":["../src/a.ts"],"sourcesContent":["export function foo(): number {\\n return 42;\\n}\\n"],"names":[],"mappings":"AAAO,SAAS,GAAc,GAAA;AAC5B,EAAO,OAAA,EAAA;AACT;;;;"}"`; |
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,51 @@ | ||
import { describe, it, expect } from "vitest"; | ||
import fs from "node:fs"; | ||
import path from "node:path"; | ||
import { fileURLToPath } from "node:url"; | ||
import { build } from "../src/index.js"; | ||
|
||
type BuildConfig = Parameters<typeof build>[2]; | ||
|
||
describe("Build fixtures", () => { | ||
const tests: [string, BuildConfig & { dir: string }][] = [ | ||
[ | ||
"declaration (mkdist)", | ||
{ | ||
dir: "fixtures/mkdist-declaration", | ||
}, | ||
], | ||
[ | ||
"sourcemap (mkdist)", | ||
{ | ||
dir: "fixtures/mkdist-sourcemap", | ||
}, | ||
], | ||
[ | ||
"declaration (rollup)", | ||
{ | ||
dir: "fixtures/rollup-declaration", | ||
}, | ||
], | ||
[ | ||
"sourcemap (rollup)", | ||
{ | ||
dir: "fixtures/rollup-sourcemap", | ||
}, | ||
], | ||
]; | ||
|
||
it.each(tests)("%s", async (_, { dir, ...buildOptions }) => { | ||
const cwd = new URL(dir.replace(/\/?$/, "/"), import.meta.url); | ||
await build(fileURLToPath(cwd), false, buildOptions); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note: the tests are set up to allow any build options if needed, even though this currently doesn’t take use of that. But we could test stubs, etc. if needed! (Should we add more tests for those?) |
||
for (const file of fs.readdirSync(new URL("dist/", cwd), { | ||
recursive: true, | ||
withFileTypes: true, | ||
})) { | ||
if (file.isFile()) { | ||
expect( | ||
fs.readFileSync(path.join(file.parentPath, file.name), "utf8"), | ||
).toMatchSnapshot(file.name); | ||
} | ||
} | ||
}); | ||
}); |
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
test/fixture/build.config.ts → test/fixtures/default/build.config.ts
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
2 changes: 1 addition & 1 deletion
2
test/fixture/build.preset.ts → test/fixtures/default/build.preset.ts
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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,12 @@ | ||
import { defineBuildConfig } from "../../../src/index.js"; | ||
|
||
export default defineBuildConfig({ | ||
entries: [ | ||
{ | ||
input: "./src/", | ||
builder: "mkdist", | ||
}, | ||
], | ||
outDir: "./dist/", | ||
declaration: true, | ||
}); |
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,3 @@ | ||
export function foo(): number { | ||
return 42; | ||
} |
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 @@ | ||
export { foo } from "./a.js"; |
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,12 @@ | ||
import { defineBuildConfig } from "../../../src/index.js"; | ||
|
||
export default defineBuildConfig({ | ||
entries: [ | ||
{ | ||
input: "./src/", | ||
builder: "mkdist", | ||
}, | ||
], | ||
outDir: "./dist/", | ||
sourcemap: true, | ||
}); |
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,3 @@ | ||
export function foo(): number { | ||
return 42; | ||
} |
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 @@ | ||
export { foo } from "./a.js"; |
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,15 @@ | ||
import { defineBuildConfig } from "../../../src/index.js"; | ||
|
||
export default defineBuildConfig({ | ||
entries: [ | ||
{ | ||
input: "./src/index.ts", | ||
builder: "rollup", | ||
}, | ||
], | ||
outDir: "./dist/", | ||
declaration: true, | ||
rollup: { | ||
emitCJS: true, | ||
}, | ||
}); |
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,3 @@ | ||
export function foo(): number { | ||
return 42; | ||
} |
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 @@ | ||
export { foo } from "./a.js"; |
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,15 @@ | ||
import { defineBuildConfig } from "../../../src/index.js"; | ||
|
||
export default defineBuildConfig({ | ||
entries: [ | ||
{ | ||
input: "./src/index.ts", | ||
builder: "rollup", | ||
}, | ||
], | ||
outDir: "./dist/", | ||
sourcemap: true, | ||
rollup: { | ||
emitCJS: true, | ||
}, | ||
}); |
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,3 @@ | ||
export function foo(): number { | ||
return 42; | ||
} |
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 @@ | ||
export { foo } from "./a.js"; |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: this test revealed that
mkdist
doesn’t supportsourcemap: true
. Should it?I figured that this test is just a recording of the current behavior (and can surface other bugs like this!)