Skip to content

Commit 4e299e5

Browse files
committed
Enhance CI workflow and improve package consumption tests
- Updated the CI workflow to verify TypeScript types more effectively by removing unnecessary arguments. - Improved ESM and CommonJS consumer tests to assert the correct types of imported functions, ensuring proper functionality of the Reflex library. - Added error handling in the library packing functions to check for the existence of tarballs, enhancing reliability during the packaging process. - Adjusted argument filtering in the main function to handle pnpm's argument parsing more accurately. These changes aim to strengthen the testing framework and ensure robust package consumption.
1 parent b6a1b29 commit 4e299e5

3 files changed

Lines changed: 42 additions & 8 deletions

File tree

  • .github/workflows
  • packages
    • reflex-persist/tests/package-consumer
    • reflex/tests/legacy-consumer

.github/workflows/ci.yml

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ jobs:
133133

134134
- name: Verify packed tarball (runtime smoke + TypeScript ${{ matrix.typescript }})
135135
run: >-
136-
pnpm --filter @flexsurfer/reflex run test:types:legacy --
136+
pnpm --filter @flexsurfer/reflex run test:types:legacy
137137
${{ matrix.typescript }}
138138
139139
test-matrix:
@@ -214,7 +214,13 @@ jobs:
214214
cd test-consumption/esm-consumer
215215
npm init -y
216216
npm install ../../reflex.tgz react@19.2.8
217-
echo 'import { initState, dispatch } from "@flexsurfer/reflex"; console.log("ESM import works");' > test.mjs
217+
cat > test.mjs <<'EOF'
218+
import assert from 'node:assert/strict';
219+
import { createReflexRuntime, useSubscription } from '@flexsurfer/reflex';
220+
assert.equal(typeof createReflexRuntime, 'function');
221+
assert.equal(typeof useSubscription, 'function');
222+
console.log('ESM import works');
223+
EOF
218224
node test.mjs
219225
220226
# Test CommonJS consumption
@@ -223,7 +229,13 @@ jobs:
223229
cd cjs-consumer
224230
npm init -y
225231
npm install ../../reflex.tgz react@19.2.8
226-
echo 'const { initState, dispatch } = require("@flexsurfer/reflex"); console.log("CommonJS require works");' > test.js
232+
cat > test.js <<'EOF'
233+
const assert = require('node:assert/strict');
234+
const { createReflexRuntime, useSubscription } = require('@flexsurfer/reflex');
235+
assert.equal(typeof createReflexRuntime, 'function');
236+
assert.equal(typeof useSubscription, 'function');
237+
console.log('CommonJS require works');
238+
EOF
227239
node test.js
228240
229241
devtools-workspaces:
@@ -382,8 +394,13 @@ jobs:
382394
383395
# Create entry file that imports from the library
384396
cat > index.js << 'EOF'
385-
import { initState } from "@flexsurfer/reflex";
386-
console.log("Successfully imported initState:", typeof initState);
397+
import { createReflexRuntime, useSubscription } from "@flexsurfer/reflex";
398+
if (typeof createReflexRuntime !== "function") {
399+
throw new Error("createReflexRuntime is not a function");
400+
}
401+
if (typeof useSubscription !== "function") {
402+
throw new Error("useSubscription is not a function");
403+
}
387404
console.log("Library bundled successfully!");
388405
EOF
389406

packages/reflex-persist/tests/package-consumer/run.mjs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,11 @@ function pack(packageRoot, destination) {
2525
);
2626
const filename = JSON.parse(output)[0]?.filename;
2727
if (!filename) throw new Error(`npm pack did not report a tarball for ${packageRoot}.`);
28-
return path.join(destination, filename);
28+
const tarball = path.join(destination, filename);
29+
if (!fs.existsSync(tarball)) {
30+
throw new Error(`npm pack reported ${filename} for ${packageRoot} but wrote no tarball.`);
31+
}
32+
return tarball;
2933
}
3034

3135
function compiler(name) {
@@ -49,6 +53,9 @@ function main() {
4953
try {
5054
process.env.npm_config_cache = path.join(workDir, '.npm-cache');
5155
process.env.npm_config_update_notifier = 'false';
56+
// `npm publish --dry-run` exports npm_config_dry_run=true to lifecycle scripts, and
57+
// prepublishOnly runs this check: without the override npm pack writes no tarball.
58+
process.env.npm_config_dry_run = 'false';
5259
const reflexTarball = pack(reflexRoot, workDir);
5360
const persistTarball = pack(persistRoot, workDir);
5461
const consumerDir = path.join(workDir, 'consumer');

packages/reflex/tests/legacy-consumer/run.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,18 @@ function packLibrary(destination, env) {
4444
if (!filename) {
4545
throw new Error('npm pack did not report a tarball filename.');
4646
}
47-
return path.join(destination, filename);
47+
const tarball = path.join(destination, filename);
48+
if (!fs.existsSync(tarball)) {
49+
throw new Error(`npm pack reported ${filename} but wrote no tarball.`);
50+
}
51+
return tarball;
4852
}
4953

5054
function main() {
51-
const requested = process.argv.slice(2).filter((version) => version.trim() !== '');
55+
// pnpm forwards the `--` separator itself into argv, so drop it alongside blanks.
56+
const requested = process.argv
57+
.slice(2)
58+
.filter((version) => version.trim() !== '' && version.trim() !== '--');
5259
const typescriptVersions = requested.length > 0 ? requested : DEFAULT_TYPESCRIPT_VERSIONS;
5360

5461
if (!fs.existsSync(path.join(repoRoot, 'dist', 'index.mjs'))) {
@@ -59,6 +66,9 @@ function main() {
5966
const env = {
6067
...process.env,
6168
npm_config_cache: path.join(workDir, 'npm-cache'),
69+
// `npm publish --dry-run` exports npm_config_dry_run=true to lifecycle scripts, and
70+
// prepublishOnly runs this check: without the override npm pack writes no tarball.
71+
npm_config_dry_run: 'false',
6272
};
6373
try {
6474
const tarball = packLibrary(workDir, env);

0 commit comments

Comments
 (0)