-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(ci-e2e): set up nx monorepo fixture and test push event
- Loading branch information
1 parent
6a6c2f3
commit 701598b
Showing
22 changed files
with
246 additions
and
10 deletions.
There are no files selected for viewing
3 changes: 3 additions & 0 deletions
3
e2e/ci-e2e/mocks/fixtures/nx-monorepo/apps/api/code-pushup.config.js
This file contains 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,3 @@ | ||
import { resolveConfig } from '../../code-pushup.preset.js'; | ||
|
||
export default resolveConfig(import.meta.url); |
This file contains 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,9 @@ | ||
{ | ||
"name": "api", | ||
"projectType": "application", | ||
"targets": { | ||
"code-pushup": { | ||
"command": "npx @code-pushup/cli --no-progress --config=apps/api/code-pushup.config.js" | ||
} | ||
} | ||
} |
This file contains 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 @@ | ||
console.log('Hello, world!'); |
3 changes: 3 additions & 0 deletions
3
e2e/ci-e2e/mocks/fixtures/nx-monorepo/apps/cms/code-pushup.config.js
This file contains 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,3 @@ | ||
import { resolveConfig } from '../../code-pushup.preset.js'; | ||
|
||
export default resolveConfig(import.meta.url); |
This file contains 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,9 @@ | ||
{ | ||
"name": "cms", | ||
"projectType": "application", | ||
"targets": { | ||
"code-pushup": { | ||
"command": "npx @code-pushup/cli --no-progress --config=apps/cms/code-pushup.config.js" | ||
} | ||
} | ||
} |
This file contains 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 @@ | ||
console.log('Hello, world!'); |
3 changes: 3 additions & 0 deletions
3
e2e/ci-e2e/mocks/fixtures/nx-monorepo/apps/web/code-pushup.config.js
This file contains 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,3 @@ | ||
import { resolveConfig } from '../../code-pushup.preset.js'; | ||
|
||
export default resolveConfig(import.meta.url); |
This file contains 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,9 @@ | ||
{ | ||
"name": "web", | ||
"projectType": "application", | ||
"targets": { | ||
"code-pushup": { | ||
"command": "npx @code-pushup/cli --no-progress --config=apps/web/code-pushup.config.js" | ||
} | ||
} | ||
} |
This file contains 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 @@ | ||
console.log('Hello, world!'); |
66 changes: 66 additions & 0 deletions
66
e2e/ci-e2e/mocks/fixtures/nx-monorepo/code-pushup.preset.js
This file contains 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,66 @@ | ||
import { dirname, join } from 'node:path'; | ||
import { fileURLToPath } from 'node:url'; | ||
import { crawlFileSystem } from '@code-pushup/utils'; | ||
|
||
export function resolveConfig(url) { | ||
const directory = fileURLToPath(dirname(url)); | ||
return { | ||
persist: { | ||
outputDir: join(directory, '.code-pushup'), | ||
}, | ||
plugins: [ | ||
{ | ||
slug: 'ts-migration', | ||
title: 'TypeScript migration', | ||
icon: 'typescript', | ||
audits: [ | ||
{ | ||
slug: 'ts-files', | ||
title: 'Source files converted from JavaScript to TypeScript', | ||
}, | ||
], | ||
runner: async () => { | ||
const paths = await crawlFileSystem({ | ||
directory, | ||
pattern: /\.[jt]s$/, | ||
}); | ||
const jsPaths = paths.filter(path => path.endsWith('.js')); | ||
const tsPaths = paths.filter(path => path.endsWith('.ts')); | ||
const jsFileCount = jsPaths.length; | ||
const tsFileCount = tsPaths.length; | ||
const ratio = tsFileCount / (jsFileCount + tsFileCount); | ||
const percentage = Math.round(ratio * 100); | ||
return [ | ||
{ | ||
slug: 'ts-files', | ||
value: percentage, | ||
score: ratio, | ||
displayValue: `${percentage}% converted`, | ||
details: { | ||
issues: jsPaths.map(file => ({ | ||
message: 'Use .ts file extension instead of .js', | ||
severity: 'warning', | ||
source: { file }, | ||
})), | ||
}, | ||
}, | ||
]; | ||
}, | ||
}, | ||
], | ||
categories: [ | ||
{ | ||
slug: 'ts-migration', | ||
title: 'TypeScript migration', | ||
refs: [ | ||
{ | ||
type: 'audit', | ||
plugin: 'ts-migration', | ||
slug: 'ts-files', | ||
weight: 1, | ||
}, | ||
], | ||
}, | ||
], | ||
}; | ||
} |
3 changes: 3 additions & 0 deletions
3
e2e/ci-e2e/mocks/fixtures/nx-monorepo/libs/ui/code-pushup.config.js
This file contains 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,3 @@ | ||
import { resolveConfig } from '../../code-pushup.preset.js'; | ||
|
||
export default resolveConfig(import.meta.url); |
This file contains 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,9 @@ | ||
{ | ||
"name": "ui", | ||
"projectType": "library", | ||
"targets": { | ||
"code-pushup": { | ||
"command": "npx @code-pushup/cli --no-progress --config=libs/ui/code-pushup.config.js" | ||
} | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
e2e/ci-e2e/mocks/fixtures/nx-monorepo/libs/ui/src/index.test.ts
This file contains 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,6 @@ | ||
import assert from 'node:assert'; | ||
import test from 'node:test'; | ||
|
||
test('1984', () => { | ||
assert.equal(2 + 2, 5); | ||
}); |
This file contains 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 @@ | ||
console.log('Hello, world!'); |
3 changes: 3 additions & 0 deletions
3
e2e/ci-e2e/mocks/fixtures/nx-monorepo/libs/utils/code-pushup.config.js
This file contains 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,3 @@ | ||
import { resolveConfig } from '../../code-pushup.preset.js'; | ||
|
||
export default resolveConfig(import.meta.url); |
9 changes: 9 additions & 0 deletions
9
e2e/ci-e2e/mocks/fixtures/nx-monorepo/libs/utils/project.json
This file contains 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,9 @@ | ||
{ | ||
"name": "utils", | ||
"projectType": "library", | ||
"targets": { | ||
"code-pushup": { | ||
"command": "npx @code-pushup/cli --no-progress --config=libs/utils/code-pushup.config.js" | ||
} | ||
} | ||
} |
This file contains 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 @@ | ||
console.log('Hello, world!'); |
6 changes: 6 additions & 0 deletions
6
e2e/ci-e2e/mocks/fixtures/nx-monorepo/libs/utils/src/index.test.js
This file contains 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,6 @@ | ||
import assert from 'node:assert'; | ||
import test from 'node:test'; | ||
|
||
test('1984', () => { | ||
assert.equal(2 + 2, 5); | ||
}); |
This file contains 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 @@ | ||
{} |
This file contains 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 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 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,91 @@ | ||
import { join } from 'node:path'; | ||
import type { SimpleGit } from 'simple-git'; | ||
import { afterEach } from 'vitest'; | ||
import { type Options, type RunResult, runInCI } from '@code-pushup/ci'; | ||
import { readJsonFile } from '@code-pushup/utils'; | ||
import { MOCK_API } from '../mocks/api'; | ||
import { type TestRepo, setupTestRepo } from '../mocks/setup'; | ||
|
||
describe('CI - monorepo mode (Nx)', () => { | ||
let repo: TestRepo; | ||
let git: SimpleGit; | ||
let options: Options; | ||
|
||
beforeEach(async () => { | ||
repo = await setupTestRepo('nx-monorepo'); | ||
git = repo.git; | ||
options = { | ||
monorepo: true, | ||
directory: repo.baseDir, | ||
}; | ||
}); | ||
|
||
afterEach(async () => { | ||
await repo.cleanup(); | ||
}); | ||
|
||
describe('push event', () => { | ||
beforeEach(async () => { | ||
await git.checkout('main'); | ||
}); | ||
|
||
it('should collect reports for all projects', async () => { | ||
await expect( | ||
runInCI( | ||
{ head: { ref: 'main', sha: await git.revparse('main') } }, | ||
MOCK_API, | ||
options, | ||
git, | ||
), | ||
).resolves.toEqual({ | ||
mode: 'monorepo', | ||
projects: expect.arrayContaining([ | ||
{ | ||
name: 'api', | ||
files: { | ||
report: { | ||
json: join(repo.baseDir, 'apps/api/.code-pushup/report.json'), | ||
md: join(repo.baseDir, 'apps/api/.code-pushup/report.md'), | ||
}, | ||
}, | ||
}, | ||
]), | ||
} satisfies RunResult); | ||
|
||
await expect( | ||
readJsonFile(join(repo.baseDir, 'apps/api/.code-pushup/report.json')), | ||
).resolves.toEqual( | ||
expect.objectContaining({ | ||
plugins: [ | ||
expect.objectContaining({ | ||
audits: [ | ||
expect.objectContaining({ | ||
score: 0, | ||
displayValue: '0% converted', | ||
}), | ||
], | ||
}), | ||
], | ||
}), | ||
); | ||
await expect( | ||
readJsonFile(join(repo.baseDir, 'libs/ui/.code-pushup/report.json')), | ||
).resolves.toEqual( | ||
expect.objectContaining({ | ||
plugins: [ | ||
expect.objectContaining({ | ||
audits: [ | ||
expect.objectContaining({ | ||
score: expect.closeTo(0.666), | ||
displayValue: '67% converted', | ||
}), | ||
], | ||
}), | ||
], | ||
}), | ||
); | ||
}); | ||
}); | ||
|
||
// TODO: pull request event | ||
}); |