-
-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🧪 test(none): improve @roots/bud-react coverage (#2615)
Way better coverage: ``` ------------------------|---------|----------|---------|---------|------------------- File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s ------------------------|---------|----------|---------|---------|------------------- All files | 97.61 | 100 | 100 | 97.61 | src | 100 | 100 | 100 | 100 | index.ts | 100 | 100 | 100 | 100 | src/babel-refresh | 100 | 100 | 100 | 100 | index.ts | 100 | 100 | 100 | 100 | src/extension | 96.55 | 100 | 100 | 96.55 | index.ts | 96.55 | 100 | 100 | 96.55 | 44-45 src/react-refresh | 100 | 100 | 100 | 100 | index.ts | 100 | 100 | 100 | 100 | src/swc-refresh | 84.61 | 100 | 100 | 84.61 | index.ts | 84.61 | 100 | 100 | 84.61 | 31-36 src/typescript-refresh | 97.5 | 100 | 100 | 97.5 | index.ts | 97.5 | 100 | 100 | 97.5 | 37 ------------------------|---------|----------|---------|---------|------------------- ``` ## Type of change **PATCH: backwards compatible change**
- Loading branch information
1 parent
e0f496d
commit 68bb006
Showing
15 changed files
with
422 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 39 additions & 4 deletions
43
sources/@roots/bud-react/test/babel-refresh/extension.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,43 @@ | ||
import Extension from '@roots/bud-react/babel-refresh' | ||
import {describe, expect, it} from 'vitest' | ||
import {beforeEach, describe, expect, it, vi} from 'vitest' | ||
|
||
import Extension from '../../src/babel-refresh' | ||
|
||
describe(`@roots/bud-react/babel-refresh`, () => { | ||
it(`should be constructable`, () => { | ||
expect(Extension).toBeInstanceOf(Function) | ||
let bud: any | ||
let extension: Extension | ||
beforeEach(async () => { | ||
bud = { | ||
babel: { | ||
setPlugin: vi.fn(), | ||
}, | ||
module: { | ||
resolve: vi.fn(async (...args) => `/test/path/`), | ||
}, | ||
} | ||
extension = new Extension(bud) | ||
}) | ||
describe(`register()`, async () => { | ||
it(`should call logger.log`, async () => { | ||
const spy = vi.spyOn(extension.logger, `log`) | ||
await extension.register(bud) | ||
|
||
expect(spy).toHaveBeenCalledWith( | ||
`Registering react-refresh-babel transformer`, | ||
) | ||
}) | ||
|
||
it(`should interface with bud.babel`, async () => { | ||
await extension.register(bud) | ||
|
||
expect(bud.babel.setPlugin).toHaveBeenCalledWith( | ||
`react-refresh/babel`, | ||
expect.arrayContaining([ | ||
`/test/path/`, | ||
{ | ||
skipEnvCheck: true, | ||
}, | ||
]), | ||
) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,102 @@ | ||
import Extension from '@roots/bud-react/extension' | ||
import {describe, expect, it} from 'vitest' | ||
import type {Bud} from '@roots/bud-framework' | ||
|
||
describe(`@roots/bud-react`, () => { | ||
it(`should be constructable`, () => { | ||
expect(Extension).toBeInstanceOf(Function) | ||
import {beforeEach, describe, expect, it, vi} from 'vitest' | ||
|
||
import DefaultExport from '../src' | ||
import Extension from '../src/extension' | ||
|
||
describe(`@roots/bud-react`, async () => { | ||
let bud: any | ||
let extension: Extension | ||
|
||
beforeEach(async () => { | ||
bud = { | ||
extensions: { | ||
add: vi.fn(), | ||
get: vi.fn(), | ||
}, | ||
module: { | ||
resolve: vi.fn(async (...args) => `/test/path/`), | ||
}, | ||
provide: vi.fn(), | ||
} as unknown as Bud | ||
|
||
extension = new Extension(bud) | ||
}) | ||
|
||
it(`should re-export @roots/bud-react/extension`, async () => { | ||
const module = await import(`../src`) | ||
expect(module.default).toBe(DefaultExport) | ||
}) | ||
|
||
describe(`boot()`, async () => { | ||
it(`should be a function`, () => { | ||
expect(extension.boot).toBeInstanceOf(Function) | ||
}) | ||
|
||
it(`should resolve react`, async () => { | ||
const spy = vi.spyOn(extension, `resolve`) | ||
await extension.boot(bud) | ||
|
||
expect(spy).toHaveBeenCalledWith( | ||
`react`, | ||
expect.stringMatching(/@roots\/bud-react\/src\/extension\/index/), | ||
) | ||
}) | ||
|
||
it(`should call bud.provide`, async () => { | ||
await extension.boot(bud) | ||
expect(bud.provide).toHaveBeenCalledWith( | ||
`/test/path/`, | ||
expect.arrayContaining([`React`]), | ||
) | ||
}) | ||
|
||
it(`should interface with swc if available`, async () => { | ||
bud.swc = { | ||
jsc: {}, | ||
setJsc: vi.fn(), | ||
setTransform: vi.fn(), | ||
} | ||
|
||
await extension.boot(bud) | ||
|
||
expect(bud.swc.setJsc).toHaveBeenCalledWith( | ||
expect.objectContaining({ | ||
transform: { | ||
react: { | ||
runtime: `automatic`, | ||
}, | ||
}, | ||
}), | ||
) | ||
|
||
expect(bud.swc.setTransform).toHaveBeenCalledWith( | ||
expect.any(Function), | ||
) | ||
}) | ||
|
||
it(`should interface with babel if available`, async () => { | ||
bud.babel = { | ||
setPreset: vi.fn(), | ||
} | ||
|
||
await extension.boot(bud) | ||
|
||
expect(bud.babel.setPreset).toHaveBeenCalledWith( | ||
`@babel/preset-react`, | ||
`/test/path/`, | ||
) | ||
}) | ||
}) | ||
|
||
describe(`get refresh()`, async () => { | ||
it(`should call bud.extensions.get when referenced`, () => { | ||
extension.refresh | ||
|
||
expect(bud.extensions.get).toHaveBeenCalledWith( | ||
`@roots/bud-react/react-refresh`, | ||
) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.