diff --git a/sources/@roots/bud-entrypoints/package.json b/sources/@roots/bud-entrypoints/package.json index 121afc2e60..14428a1f04 100644 --- a/sources/@roots/bud-entrypoints/package.json +++ b/sources/@roots/bud-entrypoints/package.json @@ -61,7 +61,8 @@ "module": "./lib/index.js", "devDependencies": { "@skypack/package-check": "0.2.2", - "@types/node": "20.12.8" + "@types/node": "20.12.8", + "vitest": "1.6.0" }, "dependencies": { "@roots/bud": "workspace:*", diff --git a/sources/@roots/bud-entrypoints/src/extension.ts b/sources/@roots/bud-entrypoints/src/extension/index.ts similarity index 100% rename from sources/@roots/bud-entrypoints/src/extension.ts rename to sources/@roots/bud-entrypoints/src/extension/index.ts diff --git a/sources/@roots/bud-entrypoints/src/index.ts b/sources/@roots/bud-entrypoints/src/index.ts index e0a885cfd8..3eec0719de 100644 --- a/sources/@roots/bud-entrypoints/src/index.ts +++ b/sources/@roots/bud-entrypoints/src/index.ts @@ -10,7 +10,7 @@ import type {ExtensionApi} from '@roots/bud-framework/extension' -import BudEntrypoints from './extension.js' +import BudEntrypoints from './extension/index.js' declare module '@roots/bud-framework' { interface Bud { diff --git a/sources/@roots/bud-entrypoints/test/extension.test.ts b/sources/@roots/bud-entrypoints/test/extension.test.ts index 74bfbdd69c..c3b3e6bcf9 100644 --- a/sources/@roots/bud-entrypoints/test/extension.test.ts +++ b/sources/@roots/bud-entrypoints/test/extension.test.ts @@ -1,8 +1,43 @@ -import Extension from '@roots/bud-entrypoints' -import {describe, expect, it} from 'vitest' +import type {Bud} from '@roots/bud-framework' + +import {factory} from '@repo/test-kit' +import EntrypointsWebpackPlugin from '@roots/entrypoints-webpack-plugin' +import {beforeEach, describe, expect, it, vi} from 'vitest' + +import BudEntrypoints from '../src/extension/index.js' +import DefaultExport from '../src/index.js' describe(`@roots/bud-entrypoints`, () => { - it(`should be constructable`, () => { - expect(Extension).toBeInstanceOf(Function) + let bud: Bud + let entrypoints: BudEntrypoints + + beforeEach(async () => { + bud = await factory() + entrypoints = new BudEntrypoints(bud) + }) + + it(`should be instantiable`, () => { + expect(entrypoints).toBeInstanceOf(BudEntrypoints) + }) + + it(`should have a default export`, () => { + expect(DefaultExport).toBe(BudEntrypoints) + }) + + it(`should have a plugin property`, () => { + expect(entrypoints.plugin).toBe(EntrypointsWebpackPlugin) + }) + + it(`should have expected default options`, () => { + expect(entrypoints.options).toStrictEqual({ + emitHtml: false, + publicPath: bud.publicPath(), + type: `object`, + }) + }) + + it(`should use the updated publicPath value if the publicPath is updated`, async () => { + bud.setPublicPath(`test/`) + expect(entrypoints.options?.publicPath).toBe(`test/`) }) }) diff --git a/sources/@roots/bud-entrypoints/vitest.config.ts b/sources/@roots/bud-entrypoints/vitest.config.ts new file mode 100644 index 0000000000..1e9fe8a39b --- /dev/null +++ b/sources/@roots/bud-entrypoints/vitest.config.ts @@ -0,0 +1,12 @@ +import {defineConfig} from 'vitest/config' + +export default defineConfig({ + test: { + coverage: { + exclude: [`**/types/*.ts`], + include: [`src/**/*.ts`], + provider: `v8`, + }, + include: [`test/**/*.test.ts`, `test/**/*.test.tsx`], + }, +}) diff --git a/yarn.lock b/yarn.lock index c7f37542dc..50cba41f94 100644 --- a/yarn.lock +++ b/yarn.lock @@ -11583,6 +11583,7 @@ __metadata: "@skypack/package-check": "npm:0.2.2" "@types/node": "npm:20.12.8" tslib: "npm:2.6.2" + vitest: "npm:1.6.0" languageName: unknown linkType: soft