Skip to content

Commit

Permalink
feat(configuration): add playwright configuration and test
Browse files Browse the repository at this point in the history
  • Loading branch information
tobua committed Apr 14, 2024
1 parent 0f528b9 commit 97b0020
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 4 deletions.
13 changes: 13 additions & 0 deletions configuration/playwright.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import type { Template } from '../types'

export const templates: Template = {} // Has no templates, highly customizable.

export function createFile() {
return {
name: 'playwright.config.ts',
contents: `import { defineConfig } from '@playwright/test'
import { playwright } from './configuration.ts'
export default defineConfig(playwright)`,
}
}
21 changes: 18 additions & 3 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,21 @@ import { existsSync } from 'node:fs'
import { join } from 'node:path'
import { it } from 'avait'
import Bun from 'bun'
import { create } from 'logua'
import * as biome from './configuration/biome'
import * as eslint from './configuration/eslint'
import * as ignore from './configuration/gitignore'
import * as playwright from './configuration/playwright'
import * as prettier from './configuration/prettier'
import * as typescript from './configuration/typescript'
import * as vscode from './configuration/vscode'
import type { Configuration } from './types'

const log = create('zero-configuration', 'blue')

// TODO validate inputs with zod.

const configurations = [
const configurations: Configuration[] = [
{
name: 'typescript',
alias: 'tsconfig',
Expand All @@ -34,6 +39,10 @@ const configurations = [
name: 'vscode',
configuration: vscode,
},
{
name: 'playwright',
configuration: playwright,
},
]

const ignores: string[] = []
Expand All @@ -43,7 +52,7 @@ const packageJson = await Bun.file('./package.json').json()
const { value: moduleContents } = await it(import(join(process.cwd(), './configuration.ts')))

if (!(moduleContents || Object.hasOwn(packageJson, 'configuration'))) {
console.warn('zero-configuration: No configurations detected')
log('No configurations detected', 'error')
}

const userConfiguration = packageJson.configuration ?? moduleContents
Expand All @@ -64,10 +73,16 @@ for (const { name, alias, configuration } of configurations) {
await Bun.write(file.name, file.contents)
ignores.push(file.name)
}

if (value === true) {
const file = configuration.createFile()
await Bun.write(file.name, file.contents)
ignores.push(file.name)
}
}

if (ignores.length === 0) {
console.warn('zero-configuration: No configurations detected')
log('No configurations detected', 'error')
}

let userIgnores: string[] = userConfiguration.ignore ?? userConfiguration.gitignore ?? []
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"types": "tsc --noEmit"
},
"dependencies": {
"avait": "^1.0.0"
"avait": "^1.0.0",
"logua": "^3.0.3"
},
"devDependencies": {
"@biomejs/biome": "^1.6.4",
Expand Down
18 changes: 18 additions & 0 deletions test/fixture/file/configuration.ts
Original file line number Diff line number Diff line change
@@ -1 +1,19 @@
import { devices } from '@playwright/test'

export const prettier = 'recommended'

export const playwright = {
fullyParallel: true,
workers: process.env.CI ? 1 : undefined,
projects: [
{
name: 'chromium',
use: { ...devices['Desktop Chrome'] },
},
],
webServer: {
command: 'bun start',
url: 'http://localhost:3000',
reuseExistingServer: !process.env.CI,
},
}
1 change: 1 addition & 0 deletions test/fixture/package/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"eslint": true,
"prettier": "recommended",
"biome": "recommended",
"playwright": true,
"tsconfig": {
"compilerOptions": {
"target": "ES6"
Expand Down
10 changes: 10 additions & 0 deletions types.ts
Original file line number Diff line number Diff line change
@@ -1 +1,11 @@
export type Template<T = object> = { [key: string]: T }

export type Configuration = {
name: string
alias?: string
configuration: {
templates: Template
// biome-ignore lint/suspicious/noExplicitAny: Will be specified in file explicitly.
createFile: (value?: any) => { name: string; contents: string }
}
}

0 comments on commit 97b0020

Please sign in to comment.