Skip to content

Commit

Permalink
🧪 test(none): improve @roots/bud-api coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
kellymears committed Jun 5, 2024
1 parent 8d16ed5 commit bf57051
Show file tree
Hide file tree
Showing 36 changed files with 523 additions and 112 deletions.
9 changes: 9 additions & 0 deletions config/vitest/config.unit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,17 @@ import shared from './config.shared'
export default defineConfig({
test: {
...shared,
alias: {
'sources/@roots/(.*)/lib/(.*)': `sources/@roots/$1/src/$2`,
},
coverage: {
enabled: false,
include: [
`sources/@roots/*/src/*.ts`,
`sources/@roots/*/src/*.tsx`,
`sources/@roots/*/src/**/*.ts`,
`sources/@roots/*/src/**/*.tsx`,
],
},
exclude: [`tests/e2e`, `**/node_modules`],
include: [
Expand Down
40 changes: 0 additions & 40 deletions sources/@roots/bud-api/src/methods/compilePaths/compilePaths.ts

This file was deleted.

49 changes: 46 additions & 3 deletions sources/@roots/bud-api/src/methods/compilePaths/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,49 @@
export {compilePaths} from './compilePaths.js'
import type {Rules} from '@roots/bud-framework'
import type {Bud, Rules} from '@roots/bud-framework'

type Source = Array<RegExp | string> | RegExp | string
import {InputError} from '@roots/bud-support/errors'
import isArray from '@roots/bud-support/isArray'
import isString from '@roots/bud-support/isString'

export type Source = Array<RegExp | string> | RegExp | string

export type Parameters = [Source, Array<`${keyof Rules & string}`>?]

export interface compilePaths {
(this: Bud, ...value: Parameters): Bud
}

export const compilePaths: compilePaths = function (sources, rules) {
const sourcesArray = isArray(sources) ? sources : [sources]

sourcesArray.forEach(source => {
if (!isString(source) && !(source instanceof RegExp)) {
throw new InputError(
`bud.compilePaths: source must be a string or a regular expression.`,
)
}
})

this.hooks.action(`build.before`, async bud => {
const keys: Array<`${keyof Rules & string}`> = (rules ??
Object.keys(bud.build.rules)) as `${keyof Rules & string}`[]

const matches = keys.map(key => {
const match = bud.build.getRule(key)

if (!match) {
throw new InputError(
`bud.compilePaths: \`${key}\` is not a valid rule name.`,
)
}

return match
})

matches.map(rule => {
bud.api.logger.log(`setting compile paths for ${rule.getTest()}`)
rule.setInclude(sourcesArray)
})
})

return this
}
8 changes: 4 additions & 4 deletions sources/@roots/bud-api/test/__snapshots__/bundle.test.ts.snap
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`bud.bundle > should set the bundle using a string 1`] = `
exports[`@roots/bud-api/methods/bundle > should set the bundle using a string 1`] = `
{
"automaticNameDelimiter": "/",
"cacheGroups": {
Expand All @@ -18,7 +18,7 @@ exports[`bud.bundle > should set the bundle using a string 1`] = `
}
`;

exports[`bud.bundle > should set the bundle using a string name and a string test 1`] = `
exports[`@roots/bud-api/methods/bundle > should set the bundle using a string name and a string test 1`] = `
{
"automaticNameDelimiter": "/",
"cacheGroups": {
Expand All @@ -36,7 +36,7 @@ exports[`bud.bundle > should set the bundle using a string name and a string tes
}
`;

exports[`bud.bundle > should set the bundle using a string name and array of strings test 1`] = `
exports[`@roots/bud-api/methods/bundle > should set the bundle using a string name and array of strings test 1`] = `
{
"automaticNameDelimiter": "/",
"cacheGroups": {
Expand All @@ -54,7 +54,7 @@ exports[`bud.bundle > should set the bundle using a string name and array of str
}
`;

exports[`bud.bundle > should set the bundle using a string name and regular expression test 1`] = `
exports[`@roots/bud-api/methods/bundle > should set the bundle using a string name and regular expression test 1`] = `
{
"automaticNameDelimiter": "/",
"cacheGroups": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`bud.define > matches snapshot 1`] = `
exports[`@roots/bud-api/methods/define > matches snapshot 1`] = `
{
"APP_DESCRIPTION": ""test app description"",
"APP_TITLE": ""bud.js test app"",
Expand Down
4 changes: 2 additions & 2 deletions sources/@roots/bud-api/test/__snapshots__/watch.test.ts.snap
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`bud.watch > [Array, Options] parameters > should add watch files and options 1`] = `
exports[`@roots/bud-api/methods/watch > [Array, Options] parameters > should add watch files and options 1`] = `
[
"1/*.js",
]
`;

exports[`bud.watch > in development > should add watch files 1`] = `
exports[`@roots/bud-api/methods/watch > in development > should add watch files 1`] = `
[
"1/*.js",
]
Expand Down
2 changes: 1 addition & 1 deletion sources/@roots/bud-api/test/alias.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {beforeAll, describe, expect, it} from 'vitest'

import {alias as aliasFn} from '../src/methods/alias/index.ts'

describe(`bud.alias`, () => {
describe(`@roots/bud-api/methods/alias`, () => {
let bud: Bud
let alias: typeof aliasFn

Expand Down
2 changes: 1 addition & 1 deletion sources/@roots/bud-api/test/assets.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {beforeEach, describe, expect, it} from 'vitest'

import {assets} from '../src/methods/assets/index.ts'

describe(`bud.assets`, () => {
describe(`@roots/bud-api/methods/assets`, () => {
let bud: Bud
let assetsFn: typeof assets

Expand Down
2 changes: 1 addition & 1 deletion sources/@roots/bud-api/test/bundle.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {beforeEach, describe, expect, it} from 'vitest'

import {bundle} from '../src/methods/bundle/index.ts'

describe(`bud.bundle`, () => {
describe(`@roots/bud-api/methods/bundle`, () => {
let bud: Bud
let instance: typeof bundle

Expand Down
Loading

0 comments on commit bf57051

Please sign in to comment.