diff --git a/src/apollo-server/__tests__/__snapshots__/index.ts.snap b/src/apollo-server/__tests__/__snapshots__/index.ts.snap index 9ad0e32c..b6feed36 100644 --- a/src/apollo-server/__tests__/__snapshots__/index.ts.snap +++ b/src/apollo-server/__tests__/__snapshots__/index.ts.snap @@ -35,7 +35,7 @@ jobs: run: npm ci - name: Execute the command run: npm run lint - unit-tests: + typecheck: runs-on: ubuntu-latest permissions: contents: read @@ -56,8 +56,8 @@ jobs: if: \${{ steps.cache-deps.outputs.cache-hit != 'true' }} run: npm ci - name: Execute the command - run: npm run test - typecheck: + run: npm run typecheck + unit-tests: runs-on: ubuntu-latest permissions: contents: read @@ -78,7 +78,7 @@ jobs: if: \${{ steps.cache-deps.outputs.cache-hit != 'true' }} run: npm ci - name: Execute the command - run: npm run typecheck + run: npm run test " `; @@ -405,7 +405,7 @@ jobs: run: npm ci - name: Execute the command run: npm run lint - unit-tests: + typecheck: runs-on: ubuntu-latest permissions: contents: read @@ -426,8 +426,8 @@ jobs: if: \${{ steps.cache-deps.outputs.cache-hit != 'true' }} run: npm ci - name: Execute the command - run: npm run test - typecheck: + run: npm run typecheck + unit-tests: runs-on: ubuntu-latest permissions: contents: read @@ -448,7 +448,7 @@ jobs: if: \${{ steps.cache-deps.outputs.cache-hit != 'true' }} run: npm ci - name: Execute the command - run: npm run typecheck + run: npm run test ", ".gitignore": "# ~~ Generated by projen. To modify, edit .projenrc.mjs and run "npx projen". !/.gitattributes diff --git a/src/cdk/__tests__/__snapshots__/index.ts.snap b/src/cdk/__tests__/__snapshots__/index.ts.snap index 074c8907..a78fd3e6 100644 --- a/src/cdk/__tests__/__snapshots__/index.ts.snap +++ b/src/cdk/__tests__/__snapshots__/index.ts.snap @@ -35,7 +35,7 @@ jobs: run: npm ci - name: Execute the command run: npm run lint - unit-tests: + typecheck: runs-on: ubuntu-latest permissions: contents: read @@ -56,8 +56,8 @@ jobs: if: \${{ steps.cache-deps.outputs.cache-hit != 'true' }} run: npm ci - name: Execute the command - run: npm run test - typecheck: + run: npm run typecheck + unit-tests: runs-on: ubuntu-latest permissions: contents: read @@ -78,7 +78,7 @@ jobs: if: \${{ steps.cache-deps.outputs.cache-hit != 'true' }} run: npm ci - name: Execute the command - run: npm run typecheck + run: npm run test " `; @@ -414,7 +414,7 @@ jobs: run: npm ci - name: Execute the command run: npm run lint - unit-tests: + typecheck: runs-on: ubuntu-latest permissions: contents: read @@ -435,8 +435,8 @@ jobs: if: \${{ steps.cache-deps.outputs.cache-hit != 'true' }} run: npm ci - name: Execute the command - run: npm run test - typecheck: + run: npm run typecheck + unit-tests: runs-on: ubuntu-latest permissions: contents: read @@ -457,7 +457,7 @@ jobs: if: \${{ steps.cache-deps.outputs.cache-hit != 'true' }} run: npm ci - name: Execute the command - run: npm run typecheck + run: npm run test ", ".gitignore": "# ~~ Generated by projen. To modify, edit .projenrc.ts and run "npx projen". !/.gitattributes diff --git a/src/common/github/__tests__/__snapshots__/index.ts.snap b/src/common/github/__tests__/__snapshots__/index.ts.snap index f2bb9ee3..9aecbf15 100644 --- a/src/common/github/__tests__/__snapshots__/index.ts.snap +++ b/src/common/github/__tests__/__snapshots__/index.ts.snap @@ -1203,28 +1203,6 @@ jobs: run: npm ci - name: Execute the command run: npm run lint - unit-tests: - runs-on: ubuntu-latest - permissions: - contents: read - steps: - - uses: actions/checkout@v3 - with: - fetch-depth: 0 - - uses: actions/setup-node@v3 - with: - node-version: 18 - - name: Cache node_modules - id: cache-deps - uses: actions/cache@v3 - with: - key: \${{ hashFiles('./package-lock.json') }} - path: ./node_modules - - name: Install dependencies - if: \${{ steps.cache-deps.outputs.cache-hit != 'true' }} - run: npm ci - - name: Execute the command - run: npm run test typecheck: runs-on: ubuntu-latest permissions: diff --git a/src/common/github/__tests__/index.ts b/src/common/github/__tests__/index.ts index 34fb3a6d..a1e0a943 100644 --- a/src/common/github/__tests__/index.ts +++ b/src/common/github/__tests__/index.ts @@ -54,9 +54,19 @@ describe('GitHub utils', () => { const snapshot = synthSnapshot(project) const workflow = YAML.parse(snapshot[testWorkflowPath]) const jobs = Object.values(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 = {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(workflow.jobs).map((j) => j.steps.at(-1)!.run) + expect(jobs).toHaveLength(3) expect(jobs).toContain('npm run test') }) @@ -66,10 +76,9 @@ describe('GitHub utils', () => { const snapshot = synthSnapshot(project) const workflow = YAML.parse(snapshot[testWorkflowPath]) const jobs = Object.values(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', () => { diff --git a/src/common/github/pull-request-test-workflow.ts b/src/common/github/pull-request-test-workflow.ts index d1e54a81..b71a6531 100644 --- a/src/common/github/pull-request-test-workflow.ts +++ b/src/common/github/pull-request-test-workflow.ts @@ -9,7 +9,7 @@ import type {WithDefaultWorkflow} from './with-default-workflow' export interface PullRequestTestOptions extends Partial>, Partial>, - Pick { + Pick { /** * Github Runner selection labels * @default ['ubuntu-latest'] @@ -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)) } @@ -96,6 +99,7 @@ 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) { @@ -103,13 +107,14 @@ export class PullRequestTest extends Component { } 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, diff --git a/src/nextjs/__tests__/__snapshots__/index.ts.snap b/src/nextjs/__tests__/__snapshots__/index.ts.snap index 89ad844f..452e2885 100644 --- a/src/nextjs/__tests__/__snapshots__/index.ts.snap +++ b/src/nextjs/__tests__/__snapshots__/index.ts.snap @@ -35,7 +35,7 @@ jobs: run: npm ci - name: Execute the command run: npm run lint - unit-tests: + typecheck: runs-on: ubuntu-latest permissions: contents: read @@ -56,8 +56,8 @@ jobs: if: \${{ steps.cache-deps.outputs.cache-hit != 'true' }} run: npm ci - name: Execute the command - run: npm run test - typecheck: + run: npm run typecheck + unit-tests: runs-on: ubuntu-latest permissions: contents: read @@ -78,7 +78,7 @@ jobs: if: \${{ steps.cache-deps.outputs.cache-hit != 'true' }} run: npm ci - name: Execute the command - run: npm run typecheck + run: npm run test " `; @@ -465,7 +465,7 @@ jobs: run: npm ci - name: Execute the command run: npm run lint - unit-tests: + typecheck: runs-on: ubuntu-latest permissions: contents: read @@ -486,8 +486,8 @@ jobs: if: \${{ steps.cache-deps.outputs.cache-hit != 'true' }} run: npm ci - name: Execute the command - run: npm run test - typecheck: + run: npm run typecheck + unit-tests: runs-on: ubuntu-latest permissions: contents: read @@ -508,7 +508,7 @@ jobs: if: \${{ steps.cache-deps.outputs.cache-hit != 'true' }} run: npm ci - name: Execute the command - run: npm run typecheck + run: npm run test ", ".gitignore": "# ~~ Generated by projen. To modify, edit .projenrc.ts and run "npx projen". !/.gitattributes diff --git a/src/sst/__tests__/__snapshots__/index.ts.snap b/src/sst/__tests__/__snapshots__/index.ts.snap index d15431d5..dce1fb67 100644 --- a/src/sst/__tests__/__snapshots__/index.ts.snap +++ b/src/sst/__tests__/__snapshots__/index.ts.snap @@ -35,7 +35,7 @@ jobs: run: npm ci - name: Execute the command run: npm run lint - unit-tests: + typecheck: runs-on: ubuntu-latest permissions: contents: read @@ -56,8 +56,8 @@ jobs: if: \${{ steps.cache-deps.outputs.cache-hit != 'true' }} run: npm ci - name: Execute the command - run: npm run test - typecheck: + run: npm run typecheck + unit-tests: runs-on: ubuntu-latest permissions: contents: read @@ -78,7 +78,7 @@ jobs: if: \${{ steps.cache-deps.outputs.cache-hit != 'true' }} run: npm ci - name: Execute the command - run: npm run typecheck + run: npm run test " `; @@ -413,7 +413,7 @@ jobs: run: npm ci - name: Execute the command run: npm run lint - unit-tests: + typecheck: runs-on: ubuntu-latest permissions: contents: read @@ -434,8 +434,8 @@ jobs: if: \${{ steps.cache-deps.outputs.cache-hit != 'true' }} run: npm ci - name: Execute the command - run: npm run test - typecheck: + run: npm run typecheck + unit-tests: runs-on: ubuntu-latest permissions: contents: read @@ -456,7 +456,7 @@ jobs: if: \${{ steps.cache-deps.outputs.cache-hit != 'true' }} run: npm ci - name: Execute the command - run: npm run typecheck + run: npm run test ", ".gitignore": "# ~~ Generated by projen. To modify, edit .projenrc.ts and run "npx projen". !/.gitattributes