Skip to content

Commit

Permalink
PLA-284 Add missing test of the playwright template
Browse files Browse the repository at this point in the history
  • Loading branch information
quesabe committed Jan 23, 2024
1 parent c137d24 commit 935b029
Show file tree
Hide file tree
Showing 3 changed files with 1,213 additions and 0 deletions.
35 changes: 35 additions & 0 deletions src/playwright/__tests__/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,32 @@
import {execSync} from 'child_process'
import {synthSnapshot} from 'projen/lib/util/synth'
import {OttofellerPlaywrightProject, OttofellerPlaywrightProjectOptions} from '..'

jest.mock('child_process')

describe('Playwright template', () => {
describe('has sample code', () => {
test('included by default', () => {
const project = new TestPlaywrightProject()
const snapshot = synthSnapshot(project)
expect(snapshot['.env.development']).toBeDefined()
expect(snapshot['common/index.ts']).toBeDefined()
expect(snapshot['data/index.ts']).toBeDefined()
expect(snapshot['pages/index.ts']).toBeDefined()
expect(snapshot['specs/auth.spec.ts']).toBeDefined()
})

test('excluded with an option', () => {
const project = new TestPlaywrightProject({sampleCode: false})
const snapshot = synthSnapshot(project)
expect(snapshot['.env.development']).not.toBeDefined()
expect(snapshot['common']).not.toBeDefined()
expect(snapshot['data']).not.toBeDefined()
expect(snapshot['pages']).not.toBeDefined()
expect(snapshot['specs']).not.toBeDefined()
})
})

test('when ejected contains only tasks created by projen', () => {
const PROJEN_EJECTING = process.env
process.env.PROJEN_EJECTING = '1'
Expand All @@ -17,6 +42,16 @@ describe('Playwright template', () => {
delete process.env.PROJEN_EJECTING
}
})

test('formats ".projenrc.ts" file after synthesis', () => {
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- TS is not aware of the Jest mock, thus casting is needed
const mockedExecSync = execSync as unknown as jest.Mock<Buffer, [string]>
const project = new TestPlaywrightProject()
project.postSynthesize()
expect(mockedExecSync).toHaveBeenCalledTimes(2)
expect(mockedExecSync).toHaveBeenCalledWith('prettier --write .projenrc.ts')
expect(mockedExecSync).toHaveBeenCalledWith('eslint --fix .projenrc.ts')
})
})

class TestPlaywrightProject extends OttofellerPlaywrightProject {
Expand Down
Loading

0 comments on commit 935b029

Please sign in to comment.