Configuration

To configure Peeky, create a peeky.config.mjs or peeky.config.ts (Typescript) file in the project root (where you run the peeky command).

import { defineConfig } from '@peeky/test'

export default defineConfig({
  // Peeky options here...
})

TIP

If you want to use peeky.config.js, you need to use the old require() and module.exports = syntax.

const { defineConfig } = require('@peeky/test')

module.exports = defineConfig({
  // Peeky options here...
})

If you are in a Vite project, you can also put Peeky config in the test option in the Vite configuration:

// vite.config.ts

import { defineConfig } from 'vite'

export default defineConfig({
  test: {
    // Peeky options here...
  },
})

Comment Pragma

Some options can be overriden using comment pragma in specific test files.

Example:

/* @peeky {
  runtimeEnv: 'dom',
  mockFs: false
} */

targetDirectory

Allows you to change the working folder for running the tests.

Example:

import path from 'path'

export default defineConfig({
  targetDirectory: path.join(__dirname, './packages/my-app'),
})

match

An array of anymatch search patterns to find the test files.

Default value is:

['**/*.(spec|test).(ts|js|mjs|cjs|jsx|tsx)', '**/__tests__/**/*.(ts|js|mjs|cjs|jsx|tsx)']

So by default Peeky will match those files:

src/features/foo.spec.js
src/features/foo.test.js
src/features/foo.test.ts
src/features/user/__tests__/foo.js
src/features/user/__tests__/foo.ts
tests/foo.spec.js

Example:

export default defineConfig({
  match: ['**/*.spec.ts', '**/__tests__/**/*.ts'],
})

ignored

Array of anymatch patterns to ignore when looking for test files. By default Peeky ignores node_modules and dist folders.

Example:

export default defineConfig({
  ignored: ['**/node_modules/**'],
})

watchMatch

Array of anymatch patterns of files that will trigger new runs in development mode. By default, Peeky watches all js and ts files in the project.

Example:

export default defineConfig({
  watchMatch: ['src/**/*.(js|ts|vue)'],
})

watchBaseDirectory

Allow to watch from a different working directory from targetDirectory, which can be very useful in a monorepo. Set to null to use the targetDirectory (default).

Example:

// packages/my-app/peeky.config.js

export default defineConfig({
  // Watch all sibling packages
  watchBaseDirectory: path.resolve(__dirname, '..'),
})

watchIgnored

Array of anymatch patterns to ignore when watching for changes. By default Peeky ignores node_modules folders.

Example:

export default defineConfig({
  watchIgnored: ['**/node_modules/**'],
})

watchThrottle

Prevent from running the tests too often in development mode when many files are being changed in a short amount of time. Unit is milliseconds. Default value is 100ms.

Example:

export default defineConfig({
  watchThrottle: 1000, // 1000ms = 1s
})

maxWorkers

Maximum number of concurrent workers (in parallel processes). The default is the number of CPU in your device minus one.

Example:

export default defineConfig({
  maxWorkers: 4,
})

emptySuiteError

Enabling this option will make the test run fail whenever a test suite is empty (it doesn't contain tests). By default this is false, so Peeky just skips empty test suites.

Example:

export default defineConfig({
  emptySuiteError: true,
})

collectCoverage

Collect coverage stats from tested files using V8's coverage engine.

Default is false.

Example:

export default defineConfig({
  collectCoverage: true,
})

You can also use the --coverage command line flag to enable coverage when using the CLI:

peeky run --coverage

coverageOptions

An object for configuring coverage (done with V8) and reporting (done with c8).

  • reportsDirectory: Path to the generate report directory.
  • report: Istanbul reporter or array of reporter to use (learn more).
  • excludeNodeModules: Exclude coverage under /node_modules/ folders.
  • all: All files in working directory (and below) that pass the include and exclude checks (below), will be loaded into the report.
  • exclude: Array of glob patterns.
  • include: Array of glob patterns.
  • extension: Only files matching these extensions will show coverage.
  • skipFull: Do not show files with 100% statement, branch, and function coverage.

Example:

export default defineConfig({
  coverageOptions: {
    reportsDirectory: './coverage',
    excludeNodeModules: true,
    exclude: [
      'coverage/**',
      'packages/*/test{,s}/**',
      '**/*.d.ts',
      'cypress/**',
      'test{,s}/**',
      'test{,-*}.{js,cjs,mjs,ts,tsx,jsx}',
      '**/*{.,-}test.{js,cjs,mjs,ts,tsx,jsx}',
      '**/__tests__/**',
      '**/{karma,rollup,webpack,vite,vitest,jest,ava,babel,nyc}.config.{js,cjs,mjs,ts}',
      '**/.{eslint,mocha}rc.{js,cjs}',
    ],
    reporter: ['text', 'html'],
    extension: ['.js', '.cjs', '.mjs', '.ts', '.tsx', '.jsx', '.vue', 'svelte'],
  },
})

runtimeEnv

Set the runtime environment for all tests. More info here.

Default is 'node'.

Example:

export default defineConfig({
  runtimeEnv: 'dom',
})

You can use comment pragma in a specific test to override the global configuration:

/* @peeky {
  runtimeEnv: 'dom'
} */

describe('DOM', () => {
  test('create a div', () => {
    // Dumb example test
    const el = document.createElement('div')
    el.innerText = 'hello'
    document.body.appendChild(el)
    expect(el.innerHTML).toBe('<div>hello</div>')

    // Test your Vue, React, etc. components here
  })
})

runtimeAvailableEnvs

Exposes custom runtime environments to be used with comment pragma in tests. More info here.

Default is {}.

Example:

import { defineConfig, TestEnvironmentBase } from '@peeky/test'

class MyEnv extends TestEnvironmentBase {
  constructor (config, context) {
    super(config, context)
  }

  create () {
    // do something
  }

  destroy () {
    // do something
  }
}

export default defineConfig({
  runtimeAvailableEnvs: {
    'my-env': MyEnv,
  },
})

Then in a test:

/* @peeky {
  runtimeEnv: 'my-env'
} */

describe('Using my custom env', () => {
  // ...
})

mockFs

Enable or disable mocking the file system to prevent writing files to the real disk when executing tests. The mocked filesystem will read existing files from disk and write changes to memory instead of the physical disk.

Default is true.

Example:

export default defineConfig({
  mockFs: false,
})

You can use comment pragma in a specific test to override the global configuration:

/* @peeky {
  mockFs: true
} */

import fs from 'fs'
import path from 'path'

describe('file system', () => {
  test('write a file', () => {
    const file = path.resolve(__dirname, './test.txt')
    // This file WILL NOT be written to disk
    fs.writeFileSync(file, 'Hello World', 'utf8')
    const contents = fs.readFileSync(file, 'utf8')
    expect(contents).toBe('Hello World')
  })
})
/* @peeky {
  mockFs: false
} */

import fs from 'fs'
import path from 'path'

describe('file system', () => {
  test('write a file', () => {
    const file = path.resolve(__dirname, './test.txt')
    // This file WILL be written to disk
    fs.writeFileSync(file, 'Hello World', 'utf8')
    const contents = fs.readFileSync(file, 'utf8')
    expect(contents).toBe('Hello World')
  })
})

buildExclude

An array of RegExp, module names or functions of the form (absolutePath: string) => boolean that should not be processed during building. This can improve performance.

Default value is [/node_modules/].

Example:

export default defineConfig({
  buildExclude: [
    /node_modules/,
    // Or:
    (absolutePath) => absolutePath.includes('/node_modules/'),
  ],
})

buildInclude

An array of RegExp, module names or functions of the form (absolutePath: string) => boolean that should be processed during building. This is useful if some packages you use are using ESM format but are not correctly set up to tell Node.js to use ESM. This takes precedence over buildExclude.

Default value is [/node_modules\/(vue|@vue|diff)/]. It will be merged with your configuration.

Example:

export default defineConfig({
  buildInclude: [
    /node_modules\/vue/,
    // Or:
    (absolutePath) => absolutePath.includes('/node_modules/vue'),
  ],
})

vite

Vite config object.

Example:

export default defineConfig({
  vite: {
    // vite options here...
  },
})

reporters

Array of reporters. Available values:

  • 'console-fancy'
  • 'console-json'

Example:

export default defineConfig({
  reporters: [
    'console-json',
  ],
})

setupFiles

Array of paths to files that will be executed before running each test file.

Example:

export default defineConfig({
  setupFiles: [
    './test/setup.ts',
  ],
})

previewSetupFiles

Array of paths to files that will be executed in the HTML previews in the UI.

Example:

export default defineConfig({
  previewSetupFiles: [
    './test/setup-preview.ts',
  ],
})

To add styles to the HTML previews, import a CSS file in the previewSetupFiles:

// ./test/setup-preview.ts

import '../src/style.css'

isolate

Isolate the environment in the threaded workers for each test. Can impact performance.

Default is false.

Example:

export default defineConfig({
  isolate: true,
})