Skip to content

Commit 5cb9c7f

Browse files
committed
chore: add test project rollup-import
1 parent f719c2d commit 5cb9c7f

File tree

8 files changed

+197
-76
lines changed

8 files changed

+197
-76
lines changed

.eslintrc.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,16 @@ module.exports = {
88
extends: [
99
//
1010
"eslint:recommended",
11+
"plugin:jest/recommended",
1112
"plugin:prettier/recommended",
1213
],
1314
overrides: [
15+
{
16+
files: ["*.mjs", "rollup*.config.js", "test.js"],
17+
parserOptions: {
18+
sourceType: "module",
19+
},
20+
},
1421
{
1522
files: "*.ts",
1623
parser: "@typescript-eslint/parser",
@@ -21,6 +28,7 @@ module.exports = {
2128
plugins: ["prettier", "@typescript-eslint"],
2229
extends: [
2330
"eslint:recommended",
31+
"plugin:jest/recommended",
2432
"plugin:@typescript-eslint/eslint-recommended",
2533
"plugin:@typescript-eslint/recommended",
2634
"plugin:prettier/recommended",

jest.config.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,9 @@ module.exports = {
77
},
88
},
99
modulePathIgnorePatterns: ["dist", "jest-ignore"],
10+
projects: [
11+
//
12+
"<rootDir>",
13+
"<rootDir>/test-projects/*",
14+
],
1015
};

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
"@semantic-release/changelog": "^5.0.1",
3939
"@semantic-release/exec": "^5.0.0",
4040
"@semantic-release/git": "^9.0.0",
41-
"@types/jest": "^26.0.24",
41+
"@types/jest": "^27.0.2",
4242
"@types/node": "^16.11.6",
4343
"@types/rimraf": "^3.0.1",
4444
"@typescript-eslint/eslint-plugin": "^4.28.3",
@@ -47,6 +47,7 @@
4747
"builtin-modules": "^3.2.0",
4848
"eslint": "^7.31.0",
4949
"eslint-config-prettier": "^8.3.0",
50+
"eslint-plugin-jest": "^25.2.2",
5051
"eslint-plugin-prettier": "^3.4.0",
5152
"husky": "^7.0.1",
5253
"jest": "^27.0.6",
@@ -91,6 +92,7 @@
9192
"access": "public"
9293
},
9394
"workspaces": [
95+
"test-projects/*",
9496
"test/built-pkg/jest-ignore"
9597
],
9698
"packageManager": "[email protected]"

src/util/test-mod.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/**
2+
* This module is only for testing
3+
*/
4+
5+
import * as path from "path";
6+
7+
export const MESSAGE = "This module is only for testing";
8+
9+
export function hello(name = "world"): string {
10+
return `Hello ${name}!`;
11+
}
12+
13+
export function testPathDelimiter(): string {
14+
return path.delimiter;
15+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import * as testMod from "tlibjs-dist/util/test-mod";
2+
3+
export { testMod };
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"private": true,
3+
"dependencies": {
4+
"tlibjs-dist": "link:../../dist"
5+
},
6+
"devDependencies": {
7+
"@rollup/plugin-node-resolve": "^13.0.6",
8+
"core-js": "^3.19.0",
9+
"rollup": "^2.58.3"
10+
}
11+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import * as path from "path";
2+
import { posix as pp } from "path";
3+
import { rollup } from "rollup";
4+
import nodeResolve from "@rollup/plugin-node-resolve";
5+
6+
const FORMATS = ["esm", "cjs"];
7+
8+
test("rollup build", async () => {
9+
const bundle = await rollup({
10+
input: path.join(__dirname, "./index.mjs"),
11+
plugins: [nodeResolve()],
12+
});
13+
14+
expect(
15+
bundle.watchFiles.map((f) => pp.relative(__dirname, f)),
16+
).toMatchSnapshot("watchFiles");
17+
18+
const outputs = await Promise.all(
19+
FORMATS.map((format) =>
20+
bundle.generate({ format }).then((out) => {
21+
const outs = out.output.map((output) => {
22+
return {
23+
type: output.type,
24+
name: output.name,
25+
fileName: output.fileName,
26+
code: output.type === "chunk" ? output.code : null,
27+
};
28+
});
29+
30+
return [format, outs];
31+
}),
32+
),
33+
);
34+
35+
expect(Object.fromEntries(outputs)).toMatchSnapshot("outputs");
36+
});

0 commit comments

Comments
 (0)