Skip to content

Commit

Permalink
Merge pull request #468 from ottofeller/test-job-only-for-enabled-jest
Browse files Browse the repository at this point in the history
Enable unit tests in PullRequestTest only with jest
  • Loading branch information
gvidon authored Dec 6, 2023
2 parents 3d52088 + 6871b59 commit 0a58010
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 60 deletions.
16 changes: 8 additions & 8 deletions src/apollo-server/__tests__/__snapshots__/index.ts.snap

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 8 additions & 8 deletions src/cdk/__tests__/__snapshots__/index.ts.snap

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 0 additions & 22 deletions src/common/github/__tests__/__snapshots__/index.ts.snap

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 12 additions & 3 deletions src/common/github/__tests__/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,19 @@ describe('GitHub utils', () => {
const snapshot = synthSnapshot(project)
const workflow = YAML.parse(snapshot[testWorkflowPath])
const jobs = Object.values<projen.github.workflows.Job>(workflow.jobs).map((j) => j.steps.at(-1)!.run)
expect(jobs).toHaveLength(3)
expect(jobs).toHaveLength(2)
expect(jobs).toContain('npm run typecheck')
expect(jobs).toContain('npm run lint')
})

test('adds test job to the test workflow if jest is enabled', () => {
const options: Partial<NodeProjectOptions> = {jest: true}
const project = new TestProject(options)
new PullRequestTest(project.github!, options)
const snapshot = synthSnapshot(project)
const workflow = YAML.parse(snapshot[testWorkflowPath])
const jobs = Object.values<projen.github.workflows.Job>(workflow.jobs).map((j) => j.steps.at(-1)!.run)
expect(jobs).toHaveLength(3)
expect(jobs).toContain('npm run test')
})

Expand All @@ -66,10 +76,9 @@ describe('GitHub utils', () => {
const snapshot = synthSnapshot(project)
const workflow = YAML.parse(snapshot[testWorkflowPath])
const jobs = Object.values<projen.github.workflows.Job>(workflow.jobs).map((j) => j.steps.at(-1)!.run)
expect(jobs).toHaveLength(3)
expect(jobs).toHaveLength(2)
expect(jobs).toContain('pnpm run typecheck')
expect(jobs).toContain('pnpm run lint')
expect(jobs).toContain('pnpm run test')
})

test('allows runsOn override', () => {
Expand Down
11 changes: 8 additions & 3 deletions src/common/github/pull-request-test-workflow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import type {WithDefaultWorkflow} from './with-default-workflow'
export interface PullRequestTestOptions
extends Partial<Pick<javascript.NodeProject, 'runScriptCommand'>>,
Partial<Pick<javascript.NodePackage, 'installCommand'>>,
Pick<NodeProjectOptions, 'workflowNodeVersion'> {
Pick<NodeProjectOptions, 'workflowNodeVersion' | 'jest'> {
/**
* Github Runner selection labels
* @default ['ubuntu-latest']
Expand Down Expand Up @@ -75,10 +75,13 @@ export class PullRequestTest extends Component {

workflow.addJobs({
lint: runScriptJob({command: 'lint', ...commonJobProps}),
'unit-tests': runScriptJob({command: 'test', ...commonJobProps}),
typecheck: runScriptJob({command: 'typecheck', ...commonJobProps}),
})

if (options.jest) {
workflow.addJob('unit-tests', runScriptJob({command: 'test', ...commonJobProps}))
}

if (options.isLighthouseEnabled) {
workflow.addJob('lighthouse', lighthouseJob(commonJobProps))
}
Expand All @@ -96,20 +99,22 @@ export class PullRequestTest extends Component {
static addToProject(project: javascript.NodeProject, options: PullRequestTestOptions & WithDefaultWorkflow) {
const hasDefaultGithubWorkflows = options.hasDefaultGithubWorkflows ?? true
const isLighthouseEnabled = options.isLighthouseEnabled ?? false
const jest = options.jest ?? true
const {runsOn, outdir, workflowNodeVersion} = options

if (!hasDefaultGithubWorkflows) {
return
}

if (project.github) {
new PullRequestTest(project.github, {isLighthouseEnabled, runsOn, workflowNodeVersion})
new PullRequestTest(project.github, {isLighthouseEnabled, jest, runsOn, workflowNodeVersion})
return
}

if (project.parent && project.parent instanceof javascript.NodeProject && project.parent.github) {
new PullRequestTest(project.parent.github, {
isLighthouseEnabled,
jest,
name: `test-${options.name}`,
outdir,
runsOn,
Expand Down
16 changes: 8 additions & 8 deletions src/nextjs/__tests__/__snapshots__/index.ts.snap

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 8 additions & 8 deletions src/sst/__tests__/__snapshots__/index.ts.snap

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 0a58010

Please sign in to comment.