Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🧪 test(none): improve coverage #2599

Merged
merged 4 commits into from
Jun 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions config/vitest/config.unit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ export default defineConfig({
...shared,
coverage: {
enabled: false,
exclude: [`sources/@roots/bud-support/**/*`],
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
Loading