Skip to content

Commit c75c329

Browse files
committed
Test the the exports of the built package.
This gives us more confidence that they can be imported from the published package by runtimes/bundlers.
1 parent 7d6353b commit c75c329

File tree

9 files changed

+80
-4
lines changed

9 files changed

+80
-4
lines changed

.github/workflows/CI.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,4 @@ jobs:
3434
- run: make clean lint-ts-biome
3535
- run: make clean lint-ts-tsc
3636
- run: make clean bun-test
37+
- run: make clean test-exports

Makefile

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,22 @@ setup:
2222
bun install --frozen-lockfile
2323

2424
.PHONY: test
25-
test: lint bun-test
25+
test: test-bun test-exports lint
2626

27-
.PHONY: bun-test
28-
bun-test:
27+
.PHONY: test-bun
28+
test-bun:
2929
bun test
3030

31+
.PHONY: test-exports
32+
test-exports: build-lib-js
33+
# Yes, this is a lot of test cases: https://github.com/cubing/icons/pull/200#issuecomment-3182362760
34+
node -- 'test/exports/test-legacy-export.js'
35+
bun run -- 'test/exports/test-legacy-export.js'
36+
bun run -- 'test/exports/test-legacy-export.ts'
37+
node -- 'test/exports/test-package-export.js'
38+
bun run -- 'test/exports/test-package-export.js'
39+
bun run -- 'test/exports/test-package-export.ts'
40+
3141
.PHONY: lint
3242
lint: setup lint-ts-biome lint-ts-tsc
3343

@@ -38,6 +48,7 @@ lint-ts-biome: build-lib-js
3848
.PHONY: lint-ts-tsc
3949
lint-ts-tsc: build-lib-types
4050
bun x tsc --noEmit --project .
51+
bun x tsc --noEmit --project ./test/exports/tsconfig.json
4152

4253
.PHONY: format
4354
format: setup

test/exports/test-legacy-export.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { default as assert } from "node:assert";
2+
import { CubingIcons } from "../../js/index.js";
3+
4+
assert(typeof CubingIcons === "object");
5+
console.log("OK");

test/exports/test-legacy-export.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { default as assert } from "node:assert";
2+
3+
let capturedConsoleErrorMessage: string | undefined;
4+
console.error = (s) => {
5+
capturedConsoleErrorMessage = s;
6+
};
7+
8+
// This must be a dynamic import to avoid being hoisted above the `console.error` modification.
9+
const { CubingIcons } = await import("../../ts");
10+
11+
assert(typeof CubingIcons === "object");
12+
assert.equal(
13+
capturedConsoleErrorMessage,
14+
"Using `@cubing/icons/ts` is deprecated. Please use `@cubing/icons/js` for the same functionality.",
15+
);
16+
console.log("OK");
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { default as assert } from "node:assert";
2+
import { CubingIcons } from "@cubing/icons/js";
3+
4+
assert(typeof CubingIcons === "object");
5+
console.log("OK");
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { default as assert } from "node:assert";
2+
3+
let capturedConsoleErrorMessage: string | undefined;
4+
console.error = (s) => {
5+
capturedConsoleErrorMessage = s;
6+
};
7+
8+
// This must be a dynamic import to avoid being hoisted above the `console.error` modification.
9+
const { CubingIcons } = await import("@cubing/icons/ts");
10+
11+
assert(typeof CubingIcons === "object");
12+
assert.equal(
13+
capturedConsoleErrorMessage,
14+
"Using `@cubing/icons/ts` is deprecated. Please use `@cubing/icons/js` for the same functionality.",
15+
);
16+
console.log("OK");

test/exports/tsconfig.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"extends": "../../node_modules/@cubing/dev-config/ts/es2022-types/tsconfig.json",
3+
"compilerOptions": {
4+
"rootDir": "../../",
5+
"paths": {
6+
"@cubing/icons": ["../"]
7+
}
8+
},
9+
"include": ["**/*"]
10+
}

tsconfig.build.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"schema": "https://json.schemastore.org/tsconfig",
3+
"extends": "./tsconfig.json",
4+
"compilerOptions": {
5+
"rootDir": "./src/js/",
6+
"outDir": "./dist/lib/@cubing/icons/js/"
7+
},
8+
"include": ["./src/js/index.ts"]
9+
}

tsconfig.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
{
22
"extends": "./node_modules/@cubing/dev-config/ts/es2022-types/tsconfig.json",
3+
"compilerOptions": {
4+
"rootDir": "."
5+
},
36
"include": ["**/*"],
4-
"exclude": ["./.temp/", "./dist/"]
7+
"exclude": ["./.temp/", "./dist/", "./test/exports/"]
58
}

0 commit comments

Comments
 (0)