Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .changeset/scope-integration-test-inputs.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
---
7 changes: 7 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ jobs:
- name: Check Dashboard links
run: pnpm lint:dashboard-links

- name: Verify integration test inputs are generated
run: node scripts/integration-test-inputs.mjs --check

- name: Verify localizations are generated
run: |
pnpm --filter @clerk/localizations generate
Expand Down Expand Up @@ -700,12 +703,16 @@ jobs:
id: integration-tests
timeout-minutes: 25
run: |
if [ "$EVENT" = "merge_group" ]; then
TURBO_ARGS="$TURBO_ARGS --force"
fi
if [ "${{ matrix.test-name }}" = "electron" ]; then
xvfb-run -a pnpm turbo test:integration:${{ matrix.test-name }} $TURBO_ARGS
else
pnpm turbo test:integration:${{ matrix.test-name }} $TURBO_ARGS
fi
env:
EVENT: ${{ github.event_name }}
CLERK_E2E_OAUTH_PROVIDER_CLIENT_SECRET: ${{ secrets.CLERK_E2E_OAUTH_PROVIDER_CLIENT_SECRET }}
CLERK_PLATFORM_API_KEY: ${{ secrets.CLERK_PLATFORM_API_KEY }}
E2E_DEBUG: '1'
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/nightly-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ jobs:
if [ "${{ matrix.test-name }}" == "nextjs" ]; then
E2E_DEBUG=1 E2E_APP_ID=quickstart.next.appRouter pnpm test:integration:base --grep @quickstart 2>&1 | tee "$OUTPUT_FILE"
else
E2E_DEBUG=1 pnpm turbo test:integration:${{ matrix.test-name }} $TURBO_ARGS --only 2>&1 | tee "$OUTPUT_FILE"
E2E_DEBUG=1 pnpm turbo test:integration:${{ matrix.test-name }} $TURBO_ARGS --only --force 2>&1 | tee "$OUTPUT_FILE"
fi
echo "exit_code=${PIPESTATUS[0]}" >> $GITHUB_OUTPUT
env:
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"format": "turbo format && node scripts/format-non-workspace.mjs",
"format:check": "turbo format:check && node scripts/format-non-workspace.mjs --check",
"preinstall": "npx only-allow pnpm",
"integration:inputs": "node scripts/integration-test-inputs.mjs",
"integration:secrets": "node ./scripts/1password-keys.mjs",
"lint": "node ./scripts/lint.mjs",
"lint:attw": "FORCE_COLOR=1 turbo lint:attw",
Expand Down
2 changes: 1 addition & 1 deletion packages/mosaic/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@clerk/mosaic",
"version": "0.2.1",
"description": "Clerk Mosaic UI components",
"description": "Clerk Mosaic UI components (cache probe)",
"keywords": [
"clerk",
"auth",
Expand Down
185 changes: 185 additions & 0 deletions scripts/integration-test-inputs.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
import fs from 'node:fs';
import path from 'node:path';

import * as prettier from 'prettier';

const ROOT = path.resolve(import.meta.dirname, '..');
const TURBO_JSON = path.join(ROOT, 'turbo.json');
const INTEGRATION = path.join(ROOT, 'integration');
const TASK_PREFIX = '//#test:integration:';
const RUNTIME_PACKAGES = ['@clerk/clerk-js', '@clerk/ui', '@clerk/testing'];
const DEPENDENCY_FIELDS = ['dependencies', 'devDependencies', 'peerDependencies', 'optionalDependencies'];
const CLERK_PACKAGE = /@clerk\/[a-z0-9-]+/g;
const SKIPPED_DIRS = new Set(['node_modules', '.next', 'dist', 'playwright-report', 'test-results']);

const SUITE_SCOPED_APPS = [
{
suite: 'mosaic',
preset: 'integration/presets/next.ts',
config: 'appRouterMosaic',
template: 'integration/templates/next-app-router-mosaic',
tests: 'integration/tests/mosaic',
},
];

function readWorkspacePackages() {
const packages = new Map();
for (const dir of fs.readdirSync(path.join(ROOT, 'packages'))) {
const manifestPath = path.join(ROOT, 'packages', dir, 'package.json');
if (!fs.existsSync(manifestPath)) {
continue;
}
const manifest = JSON.parse(fs.readFileSync(manifestPath, 'utf8'));
const deps = new Set(DEPENDENCY_FIELDS.flatMap(field => Object.keys(manifest[field] ?? {})));
packages.set(manifest.name, { dir, deps });
}
return packages;
}

function closure(roots, workspace) {
const seen = new Set();
const queue = [...roots].filter(name => workspace.has(name));
while (queue.length) {
const name = queue.pop();
if (seen.has(name)) {
continue;
}
seen.add(name);
for (const dep of workspace.get(name).deps) {
if (workspace.has(dep) && !seen.has(dep)) {
queue.push(dep);
}
}
}
return seen;
}

function* walk(dir, skip) {
for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
const full = path.join(dir, entry.name);
if (skip.has(path.relative(ROOT, full))) {
continue;
}
if (entry.isDirectory()) {
if (!SKIPPED_DIRS.has(entry.name)) {
yield* walk(full, skip);
}
} else if (entry.isFile()) {
yield full;
}
}
}

function configStatement(source, scoped) {
const match = source.match(new RegExp(`const ${scoped.config} = [\\s\\S]*?;\\n`));
if (!match) {
throw new Error(`Could not find \`const ${scoped.config} = ...;\` in ${scoped.preset}`);
}
return match[0];
}

function referencedPackages(scopedApps) {
const skip = new Set(scopedApps.flatMap(scoped => [scoped.template, scoped.tests]));
const found = new Set(RUNTIME_PACKAGES);
for (const file of walk(INTEGRATION, skip)) {
let source = fs.readFileSync(file, 'utf8');
const relative = path.relative(ROOT, file);
for (const scoped of scopedApps) {
if (relative === scoped.preset) {
source = source.replace(configStatement(source, scoped), '');
}
if (relative.startsWith('integration/tests/') && new RegExp(`\\b${scoped.config}\\b`).test(source)) {
throw new Error(
`${relative} boots \`${scoped.config}\`, which is scoped to the \`${scoped.suite}\` suite. Move the test into ${scoped.tests} or remove the entry from SUITE_SCOPED_APPS.`,
);
}
}
for (const name of source.match(CLERK_PACKAGE) ?? []) {
found.add(name);
}
}
return found;
}

function scopedPackages(scoped) {
const found = new Set();
const presetSource = fs.readFileSync(path.join(ROOT, scoped.preset), 'utf8');
const sources = [configStatement(presetSource, scoped)];
for (const dir of [scoped.template, scoped.tests]) {
for (const file of walk(path.join(ROOT, dir), new Set())) {
sources.push(fs.readFileSync(file, 'utf8'));
}
}
for (const source of sources) {
for (const name of source.match(CLERK_PACKAGE) ?? []) {
found.add(name);
}
}
return found;
}

function excludedPackageGlobs(used, workspace) {
return [...workspace.entries()]
.filter(([name]) => !used.has(name))
.map(([, { dir }]) => `!packages/${dir}/**`)
.sort();
}

function computeExcludes() {
const workspace = readWorkspacePackages();
const shared = closure(referencedPackages(SUITE_SCOPED_APPS), workspace);
const excludes = { default: excludedPackageGlobs(shared, workspace) };
for (const scoped of SUITE_SCOPED_APPS) {
const used = closure([...shared, ...scopedPackages(scoped)], workspace);
excludes[scoped.suite] = excludedPackageGlobs(used, workspace);
}
const scopedDirs = SUITE_SCOPED_APPS.map(scoped => ({
suite: scoped.suite,
globs: [`!${scoped.template}/**`, `!${scoped.tests}/**`],
}));
return { excludes, scopedDirs };
}

function isManaged(input) {
return (
/^!packages\/[^*/]+\/\*\*$/.test(input) ||
SUITE_SCOPED_APPS.some(scoped => input === `!${scoped.template}/**` || input === `!${scoped.tests}/**`)
);
}

async function render() {
const turbo = JSON.parse(fs.readFileSync(TURBO_JSON, 'utf8'));
const { excludes, scopedDirs } = computeExcludes();
for (const [task, config] of Object.entries(turbo.tasks)) {
if (!task.startsWith(TASK_PREFIX)) {
continue;
}
const suite = task.slice(TASK_PREFIX.length);
const otherScopedDirs = scopedDirs.filter(scoped => scoped.suite !== suite).flatMap(scoped => scoped.globs);
config.inputs = [
...config.inputs.filter(input => !isManaged(input)),
...(excludes[suite] ?? excludes.default),
...otherScopedDirs,
];
}
const options = await prettier.resolveConfig(TURBO_JSON);
return prettier.format(JSON.stringify(turbo, null, 2), { ...options, filepath: TURBO_JSON });
}

const next = await render();
const current = fs.readFileSync(TURBO_JSON, 'utf8');

if (process.argv.includes('--check')) {
if (next !== current) {
console.error(
'turbo.json integration test inputs are out of date. Run `pnpm integration:inputs` and commit the result.',
);
process.exit(1);
}
console.log('turbo.json integration test inputs are up to date.');
} else if (next !== current) {
fs.writeFileSync(TURBO_JSON, next);
console.log('Updated integration test inputs in turbo.json.');
} else {
console.log('turbo.json integration test inputs are already up to date.');
}
Loading
Loading