Skip to content

Commit 82b5c08

Browse files
feat: add environment variable to assert 'use client' directive in CI tests
1 parent 7688362 commit 82b5c08

2 files changed

Lines changed: 14 additions & 9 deletions

File tree

.github/workflows/test.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,3 +85,5 @@ jobs:
8585

8686
- name: Build bundles and assert 'use client' directive
8787
run: npm run test:dist
88+
env:
89+
ASSERT_USE_CLIENT: '1'

__tests__/use-client-directive.test.tsx

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@
1111
* are the CJS (main) and ESM (module) outputs; the UMD <script> builds
1212
* intentionally do NOT carry it.
1313
*
14-
* dist/ is not built by `npm test` (which is just `jest --coverage`). Locally,
15-
* when the bundles are absent these tests skip with a clear message; run
16-
* `npm run test:dist` to build first and assert against fresh output. Under CI
17-
* (process.env.CI) missing bundles are a hard error rather than a silent skip,
18-
* so the guarantee can never masquerade as a pass. Files are read as TEXT
19-
* (never imported), so nothing here is pulled into coverage collection.
14+
* dist/ is not built by `npm test` (which is just `jest --coverage`), so when the
15+
* bundles are absent these tests skip with a clear message. Run `npm run test:dist`
16+
* to build first and assert against fresh output. The dedicated CI job sets
17+
* ASSERT_USE_CLIENT, under which missing bundles are a hard error rather than a
18+
* silent skip, so the guarantee can never masquerade as a pass. Files are read as
19+
* TEXT (never imported), so nothing here is pulled into coverage collection.
2020
*/
2121
import { existsSync, readFileSync } from 'fs';
2222
import { resolve } from 'path';
@@ -52,10 +52,13 @@ const umdBundles = ['auth0-react.js', 'auth0-react.min.js'];
5252
const distBuilt = [...rscBundles, ...umdBundles].every((f) => existsSync(dist(f)));
5353

5454
if (!distBuilt) {
55-
if (process.env.CI) {
55+
// The dedicated CI job sets ASSERT_USE_CLIENT (after building the bundles), so a
56+
// missing dist/ there is a hard error (the guarantee can never silently pass). Any
57+
// other run (e.g. `npm test`, which doesn't build) just skips.
58+
if (process.env.ASSERT_USE_CLIENT) {
5659
throw new Error(
57-
"dist/ bundles are missing but CI must assert the 'use client' directive. " +
58-
'Ensure the build runs before jest (see the `test:dist` script / rsc-directive CI job).'
60+
"dist/ bundles are missing but the 'use client' directive must be asserted. " +
61+
'Run `npm run test:dist`, which builds the bundles before running this suite.'
5962
);
6063
}
6164
console.warn(

0 commit comments

Comments
 (0)