-
Notifications
You must be signed in to change notification settings - Fork 6
test: add angular test matrix #85
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
Open
Orkuncakilkaya
wants to merge
33
commits into
main
Choose a base branch
from
angular-test-matrix
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
33 commits
Select commit
Hold shift + click to select a range
c6429cd
test: add angular test matrix
Orkuncakilkaya b46b7f3
test: add gen project version command before tests ran
Orkuncakilkaya 72c94fb
Merge branch 'main' into angular-test-matrix
Orkuncakilkaya 5e5762c
refactor: test-matrix bash to javascript
Orkuncakilkaya 64e83d8
refactor: node version and ci workflow adaptation
Orkuncakilkaya e7b9c06
refactor: ensure jest, build and dependencies for each major
Orkuncakilkaya 360c7c0
refactor: if else blocks to map
Orkuncakilkaya f0efde5
refactor: remove redundant fs wrappers
Orkuncakilkaya 638125b
refactor: throw error if pnpm not installed
Orkuncakilkaya a995db2
refactor: remove CI from hardcoded env
Orkuncakilkaya 3de9b6e
refactor: remove redundant main wrapper function
Orkuncakilkaya f16e4d8
refactor: simplify test matrix
Orkuncakilkaya bfd5faf
refactor: adjust angular tag logic and update pnpm version in CI work…
Orkuncakilkaya be5df1e
refactor: remove redundant comments
Orkuncakilkaya 5591907
chore: run gen version before test matrix
Orkuncakilkaya b5edb34
refactor: update pnpm-workspace with allowBuilds configuration
Orkuncakilkaya 8bf21af
refactor: update dependencies and adjust test matrix configuration
Orkuncakilkaya 90385bb
refactor: migrate to TypeScript, simplify metadata handling, and upda…
Orkuncakilkaya 8ee86ea
refactor: handle child process errors in helpers
Orkuncakilkaya 555f08b
refactor: use `parseArgs` for version argument parsing in test matrix
Orkuncakilkaya 28258f5
refactor: simplify package installation logic and replace custom recu…
Orkuncakilkaya c89b9d9
refactor: update pnpm version to 11 in CI workflow
Orkuncakilkaya 257fdaf
refactor: revert - downgrade pnpm version to 9 in CI workflow to work…
Orkuncakilkaya 248291e
refactor: revert lock file
Orkuncakilkaya a3fe125
refactor: install ts dependencies for ci
Orkuncakilkaya a720012
refactor: update frozen lockfile
Orkuncakilkaya 0f8baf1
refactor: adapt for pnpm v11
Orkuncakilkaya 230ba68
refactor: adapt for pnpm v9
Orkuncakilkaya ed5b65b
refactor: simplify test matrix version argument in CI workflow
Orkuncakilkaya c48b11a
refactor: remove property from Angular metadata
Orkuncakilkaya bb45142
refactor: remove version generation step from CI test matrix workflow
Orkuncakilkaya 3cdc8ca
refactor: adjust concurrency in test-matrix workflow
Orkuncakilkaya cb62c04
chore: try concurrency with new push
Orkuncakilkaya 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| name: Test Angular Matrix | ||
|
|
||
| on: | ||
| pull_request: | ||
|
|
||
| concurrency: | ||
| group: ${{ github.workflow }}-${{ github.head_ref || github.ref_name }} | ||
| cancel-in-progress: true | ||
|
|
||
| jobs: | ||
| test-matrix: | ||
| name: Angular ${{ matrix.angular }} | ||
| runs-on: ubuntu-latest | ||
| strategy: | ||
| fail-fast: false | ||
| matrix: | ||
| include: | ||
| - angular: 15 | ||
| node: 18 | ||
| - angular: 16 | ||
| node: 18 | ||
| - angular: 17 | ||
| node: 18 | ||
| - angular: 18 | ||
| node: 20 | ||
| - angular: 19 | ||
| node: 20 | ||
| - angular: 20 | ||
| node: 20 | ||
| - angular: 21 | ||
|
JuroUhlar marked this conversation as resolved.
|
||
| node: 22 | ||
|
|
||
| steps: | ||
| - uses: actions/checkout@v4 | ||
|
|
||
| - name: Setup Node.js ${{ matrix.node }} | ||
| uses: actions/setup-node@v4 | ||
| with: | ||
| node-version: ${{ matrix.node }} | ||
|
|
||
| - name: Install pnpm | ||
| uses: pnpm/action-setup@v4 | ||
| with: | ||
| version: 9 | ||
|
|
||
| - name: Install dependencies | ||
| run: pnpm install | ||
|
|
||
| - name: Run Matrix Check for Angular ${{ matrix.angular }} | ||
| run: pnpm run test:matrix --version=${{ matrix.angular }} | ||
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 @@ | ||
| 18 |
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,188 @@ | ||
| import * as fs from 'fs' | ||
| import * as path from 'path' | ||
| import * as os from 'os' | ||
| import { angularMetadata } from './utils/angularMetadata' | ||
| import { setupLogDir, executeCommand, updateJsonFile } from './utils/helpers' | ||
| import { parseArgs } from 'node:util' | ||
|
|
||
| const LIB_NAME = 'fingerprintjs-pro-angular' | ||
| const LOG_DIR = path.join(process.cwd(), 'test-logs') | ||
|
|
||
| process.env['NG_CLI_ANALYTICS'] = 'false' | ||
|
|
||
| async function testVersion(version: string): Promise<number> { | ||
| const meta = angularMetadata[version] | ||
| if (!meta) { | ||
| const errorMsg = `No metadata found for version ${version}` | ||
| console.error(errorMsg) | ||
| const logFile = path.join(LOG_DIR, `angular-${version}.log`) | ||
| fs.writeFileSync(logFile, errorMsg) | ||
| return 1 | ||
| } | ||
|
|
||
| const logFile = path.join(LOG_DIR, `angular-${version}.log`) | ||
| const logStream = fs.createWriteStream(logFile) | ||
| const log = (data: string) => logStream.write(data) | ||
|
|
||
| const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'angular-test-')) | ||
| const workspaceDir = path.join(tempDir, 'test-workspace') | ||
|
|
||
| try { | ||
| log(`Angular ${version}: Starting check...\n`) | ||
| console.log(`Angular ${version}: Starting check...`) | ||
|
|
||
| await executeCommand( | ||
| 'npx', | ||
| [ | ||
| '-y', | ||
| `@angular/cli@${version}`, | ||
| 'new', | ||
| 'test-workspace', | ||
| '--create-application=false', | ||
| '--skip-git', | ||
| '--skip-install', | ||
| '--defaults', | ||
| '--package-manager=pnpm', | ||
| ], | ||
| { cwd: tempDir, env: { ...process.env } }, | ||
| log | ||
| ) | ||
|
|
||
| await executeCommand( | ||
| 'npx', | ||
| ['-y', `@angular/cli@${version}`, 'generate', 'library', LIB_NAME, '--skip-install'], | ||
| { cwd: workspaceDir, env: { ...process.env } }, | ||
| log | ||
| ) | ||
|
|
||
| const angularVersionTag = parseInt(version) > 15 ? `v${version}-lts` : `^${version}` | ||
|
|
||
| const extraPackagesToInstall = [`zone.js@${meta.zone}`, `@angular/platform-browser-dynamic@${angularVersionTag}`] | ||
|
|
||
| const jestVersion = meta.jest | ||
| const typesJestVersion = meta.typesJest || jestVersion | ||
|
|
||
| const extraDevPackagesToInstall = [ | ||
| '@fingerprint/agent', | ||
| `jest-preset-angular@${meta.jpa}`, | ||
| `jest@${jestVersion}`, | ||
| `jest-environment-jsdom@${jestVersion}`, | ||
| `@types/jest@${typesJestVersion}`, | ||
| '@types/node', | ||
| ] | ||
|
|
||
| const commonOptions = [ | ||
| '--config.strict-peer-dependencies=false', | ||
| '--no-lockfile', | ||
| '--config.fund=false', | ||
| '--ignore-scripts', | ||
| ] | ||
|
|
||
| await executeCommand( | ||
| 'pnpm', | ||
| ['add', ...extraPackagesToInstall, ...extraDevPackagesToInstall, ...commonOptions], | ||
| { cwd: workspaceDir, env: { ...process.env } }, | ||
| log | ||
| ) | ||
|
|
||
| const libDestDir = path.join(workspaceDir, 'projects', LIB_NAME, 'src', 'lib') | ||
| fs.mkdirSync(libDestDir, { recursive: true }) | ||
| fs.cpSync(path.join(process.cwd(), 'projects', LIB_NAME, 'src', 'lib'), libDestDir, { recursive: true }) | ||
|
|
||
| fs.copyFileSync( | ||
| path.join(process.cwd(), 'projects', LIB_NAME, 'src', 'public-api.ts'), | ||
| path.join(workspaceDir, 'projects', LIB_NAME, 'src', 'public-api.ts') | ||
| ) | ||
|
|
||
| const rootFiles = ['jest.config.js', 'tsconfig.json', 'tsconfig.spec.json', 'test.ts'] | ||
| for (const file of rootFiles) { | ||
| const src = path.join(process.cwd(), file) | ||
| if (fs.existsSync(src)) { | ||
| fs.copyFileSync(src, path.join(workspaceDir, file)) | ||
| } | ||
| } | ||
|
|
||
| const projectDir = path.join(workspaceDir, 'projects', LIB_NAME) | ||
| const projectFiles = [ | ||
| 'ng-package.json', | ||
| 'package.json', | ||
| 'tsconfig.lib.json', | ||
| 'tsconfig.lib.prod.json', | ||
| 'tsconfig.spec.json', | ||
| ] | ||
| for (const file of projectFiles) { | ||
| fs.copyFileSync(path.join(process.cwd(), 'projects', LIB_NAME, file), path.join(projectDir, file)) | ||
| } | ||
|
|
||
| const tsconfigFiles = [ | ||
| path.join(workspaceDir, 'tsconfig.json'), | ||
| path.join(workspaceDir, 'projects', LIB_NAME, 'tsconfig.spec.json'), | ||
| ] | ||
| for (const file of tsconfigFiles) { | ||
| if (fs.existsSync(file)) { | ||
| updateJsonFile(file, (json) => { | ||
| if (!json.compilerOptions) { | ||
| json.compilerOptions = {} | ||
| } | ||
| json.compilerOptions.skipLibCheck = true | ||
| json.compilerOptions.esModuleInterop = true | ||
| if (parseInt(version) >= 21) { | ||
| json.compilerOptions.moduleResolution = 'bundler' | ||
| } | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| await executeCommand( | ||
| './node_modules/.bin/ng', | ||
| ['build', LIB_NAME], | ||
| { cwd: workspaceDir, env: { ...process.env } }, | ||
| log | ||
| ) | ||
|
|
||
| await executeCommand('./node_modules/.bin/jest', [], { cwd: workspaceDir, env: { ...process.env } }, log) | ||
|
|
||
| console.log(`Angular ${version}: PASSED`) | ||
| return 0 | ||
| } catch (err: any) { | ||
| log(err.stack || err.message) | ||
| return 1 | ||
| } finally { | ||
| logStream.end() | ||
| fs.rmSync(tempDir, { recursive: true, force: true }) | ||
| } | ||
| } | ||
|
|
||
| setupLogDir(LOG_DIR) | ||
|
|
||
| const { version: versionsParsed } = parseArgs({ | ||
| options: { | ||
| version: { | ||
| type: 'string', | ||
| multiple: true, | ||
| short: 'v', | ||
| }, | ||
| }, | ||
| }).values | ||
| const versionArgs: string[] = versionsParsed ?? [] | ||
|
|
||
| const versionsToTest = versionArgs.length > 0 ? versionArgs : Object.keys(angularMetadata) | ||
|
|
||
| async function run() { | ||
| console.log(`Starting matrix tests for: ${versionsToTest.join(', ')}`) | ||
|
|
||
| const results = await Promise.all(versionsToTest.map((version) => testVersion(version))) | ||
| const failed = results.some((code) => code !== 0) | ||
|
|
||
| if (failed) { | ||
| process.exit(1) | ||
| } else { | ||
| console.log('Success: All versions passed') | ||
| process.exit(0) | ||
| } | ||
| } | ||
|
|
||
| run().catch((err) => { | ||
| console.error(err) | ||
| process.exit(1) | ||
| }) |
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,16 @@ | ||
| export interface AngularVersionMetadata { | ||
| zone: string | ||
| jpa: string | ||
| jest: string | ||
| typesJest?: string | ||
| } | ||
|
|
||
| export const angularMetadata: Record<string, AngularVersionMetadata> = { | ||
| 15: { zone: '~0.11.4', jpa: '^13.1.4', jest: '^29.0.0' }, | ||
| 16: { zone: '~0.13.3', jpa: '^13.1.4', jest: '^29.0.0' }, | ||
| 17: { zone: '~0.14.4', jpa: '^14.1.1', jest: '^29.0.0' }, | ||
| 18: { zone: '~0.14.4', jpa: '^14.1.1', jest: '^29.0.0' }, | ||
| 19: { zone: '~0.15.0', jpa: '^14.4.2', jest: '^29.0.0' }, | ||
| 20: { zone: '~0.15.0', jpa: '^15.0.0', jest: '^30.2.0', typesJest: '^30.0.0' }, | ||
| 21: { zone: '~0.16.0', jpa: '^17.0.0', jest: '^30.2.0', typesJest: '^30.0.0' }, | ||
| } |
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,47 @@ | ||
| import * as fs from 'fs' | ||
| import * as path from 'path' | ||
| import { spawn, SpawnOptions } from 'child_process' | ||
| import { parse, stringify } from 'comment-json' | ||
|
|
||
| export function setupLogDir(logDir: string): void { | ||
| if (!fs.existsSync(logDir)) { | ||
| fs.mkdirSync(logDir, { recursive: true }) | ||
| } else { | ||
| fs.readdirSync(logDir).forEach((file) => { | ||
| fs.unlinkSync(path.join(logDir, file)) | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| export function executeCommand( | ||
| cmd: string, | ||
| args: string[], | ||
| opts: SpawnOptions, | ||
| log?: (data: string) => void | ||
| ): Promise<void> { | ||
| return new Promise((resolve, reject) => { | ||
| const child = spawn(cmd, args, opts) | ||
| if (log) { | ||
| child.stdout?.on('data', (data) => log(data.toString())) | ||
| child.stderr?.on('data', (data) => log(data.toString())) | ||
| } | ||
| child.on('close', (code) => { | ||
| if (code === 0) { | ||
| resolve() | ||
| } else { | ||
| reject(new Error(`Command failed with code ${code}: ${cmd} ${args.join(' ')}`)) | ||
| } | ||
| }) | ||
| child.on('error', (err) => reject(err)) | ||
| }) | ||
| } | ||
|
|
||
| export function updateJsonFile(filePath: string, updater: (json: any) => void): void { | ||
| if (!fs.existsSync(filePath)) { | ||
| return | ||
| } | ||
| const content = fs.readFileSync(filePath, 'utf8') | ||
| const json = parse(content) | ||
| updater(json) | ||
| fs.writeFileSync(filePath, stringify(json, null, 2), 'utf8') | ||
| } |
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
Oops, something went wrong.
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.