-
Notifications
You must be signed in to change notification settings - Fork 66
test: add package export smoke checks #1406
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
Merged
toddbaert
merged 2 commits into
open-feature:main
from
Herrtian:test-package-format-exports
Jun 26, 2026
+170
−0
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 hidden or 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 hidden or 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 hidden or 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,166 @@ | ||
| import { execFile } from 'node:child_process'; | ||
| import { mkdtemp, rm, writeFile } from 'node:fs/promises'; | ||
| import { tmpdir } from 'node:os'; | ||
| import { dirname, join, resolve } from 'node:path'; | ||
| import process from 'node:process'; | ||
| import { fileURLToPath } from 'node:url'; | ||
| import { promisify } from 'node:util'; | ||
|
|
||
| const execFileAsync = promisify(execFile); | ||
| const repoRoot = resolve(dirname(fileURLToPath(import.meta.url)), '..'); | ||
|
|
||
| const packageWorkspaces = ['packages/shared', 'packages/server', 'packages/web']; | ||
|
|
||
| const corePackage = '@openfeature/core'; | ||
| const sdkPackages = ['@openfeature/server-sdk', '@openfeature/web-sdk']; | ||
| const smokeTestPackages = [corePackage, ...sdkPackages]; | ||
|
|
||
| const fixtureConfig = { | ||
| 'format-check': { | ||
| variants: { | ||
| on: true, | ||
| off: false, | ||
| }, | ||
| defaultVariant: 'on', | ||
| disabled: false, | ||
| }, | ||
| }; | ||
|
|
||
| async function run(command, args, options = {}) { | ||
| try { | ||
| return await execFileAsync(command, args, { | ||
| cwd: repoRoot, | ||
| maxBuffer: 1024 * 1024 * 10, | ||
| ...options, | ||
| }); | ||
| } catch (error) { | ||
| if (error.stdout) process.stdout.write(error.stdout); | ||
| if (error.stderr) process.stderr.write(error.stderr); | ||
| throw error; | ||
| } | ||
| } | ||
|
|
||
| function npmCommand(args) { | ||
| if (process.platform === 'win32') { | ||
| return ['cmd.exe', ['/d', '/s', '/c', 'npm', ...args]]; | ||
| } | ||
|
|
||
| return ['npm', args]; | ||
| } | ||
|
|
||
| function runNpm(args, options) { | ||
| const [command, commandArgs] = npmCommand(args); | ||
| return run(command, commandArgs, options); | ||
| } | ||
|
|
||
| async function packPackage(workspace, destination) { | ||
| const packageDirectory = join(repoRoot, workspace); | ||
| const { stdout } = await runNpm(['pack', '--json', '--pack-destination', destination], { | ||
| cwd: packageDirectory, | ||
| }); | ||
| const [packResult] = JSON.parse(stdout); | ||
|
|
||
| return join(destination, packResult.filename); | ||
| } | ||
|
|
||
| function sourceFor(packageName) { | ||
| if (packageName === corePackage) { | ||
| return `import { ErrorCode, ServerProviderStatus } from '${packageName}'; | ||
|
|
||
| if (ErrorCode.FLAG_NOT_FOUND !== 'FLAG_NOT_FOUND') { | ||
| throw new Error('${packageName} did not expose ErrorCode correctly'); | ||
| } | ||
|
|
||
| if (ServerProviderStatus.NOT_READY !== 'NOT_READY') { | ||
| throw new Error('${packageName} did not expose ServerProviderStatus correctly'); | ||
| } | ||
| `; | ||
| } | ||
|
|
||
| return `import { InMemoryProvider, OpenFeature } from '${packageName}'; | ||
|
|
||
| async function main() { | ||
| const provider = new InMemoryProvider(${JSON.stringify(fixtureConfig, null, 2)} as const); | ||
| await OpenFeature.setProviderAndWait(provider); | ||
|
|
||
| const value = await OpenFeature.getClient().getBooleanValue('format-check', false); | ||
|
|
||
| if (value !== true) { | ||
| throw new Error('${packageName} did not evaluate the test flag'); | ||
| } | ||
| } | ||
|
|
||
| void main(); | ||
| `; | ||
| } | ||
|
|
||
| async function writeFixture(fixtureDirectory) { | ||
| await writeFile( | ||
| join(fixtureDirectory, 'package.json'), | ||
| JSON.stringify( | ||
| { | ||
| name: 'openfeature-package-export-check', | ||
| private: true, | ||
| version: '0.0.0', | ||
| }, | ||
| null, | ||
| 2, | ||
| ), | ||
| ); | ||
|
|
||
| await writeFile( | ||
| join(fixtureDirectory, 'tsconfig.json'), | ||
| JSON.stringify( | ||
| { | ||
| compilerOptions: { | ||
| target: 'ES2020', | ||
| module: 'Node16', | ||
| moduleResolution: 'Node16', | ||
| strict: true, | ||
| skipLibCheck: true, | ||
| outDir: 'dist', | ||
| }, | ||
| include: ['*.mts', '*.cts'], | ||
| }, | ||
| null, | ||
| 2, | ||
| ), | ||
| ); | ||
|
|
||
| for (const packageName of smokeTestPackages) { | ||
| const label = packageName.replace('@openfeature/', '').replace('-sdk', ''); | ||
| await writeFile(join(fixtureDirectory, `${label}.mts`), sourceFor(packageName)); | ||
| await writeFile(join(fixtureDirectory, `${label}.cts`), sourceFor(packageName)); | ||
| } | ||
| } | ||
|
|
||
| async function main() { | ||
| const tempDirectory = await mkdtemp(join(tmpdir(), 'openfeature-package-exports-')); | ||
|
|
||
| try { | ||
| const tarballs = []; | ||
|
|
||
| for (const packageWorkspace of packageWorkspaces) { | ||
| tarballs.push(await packPackage(packageWorkspace, tempDirectory)); | ||
| } | ||
|
|
||
| await writeFixture(tempDirectory); | ||
| await runNpm(['install', '--ignore-scripts', '--no-audit', '--no-fund', '--no-package-lock', ...tarballs], { | ||
| cwd: tempDirectory, | ||
| }); | ||
|
|
||
| await run(process.execPath, [join(repoRoot, 'node_modules/typescript/bin/tsc'), '--project', 'tsconfig.json'], { | ||
| cwd: tempDirectory, | ||
| }); | ||
|
|
||
| for (const packageName of smokeTestPackages) { | ||
| const label = packageName.replace('@openfeature/', '').replace('-sdk', ''); | ||
| await run(process.execPath, [join(tempDirectory, 'dist', `${label}.mjs`)]); | ||
| await run(process.execPath, [join(tempDirectory, 'dist', `${label}.cjs`)]); | ||
| } | ||
| } finally { | ||
| await rm(tempDirectory, { recursive: true, force: true }); | ||
| } | ||
| } | ||
|
|
||
| await main(); | ||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.