Skip to content

Commit ca7e360

Browse files
authored
Merge pull request #22 from chengpeiquan/develop
Develop
2 parents 0b0815b + 9ad2a20 commit ca7e360

5 files changed

+68
-41
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "vite-plugin-banner",
33
"description": "A banner plugin for Vite. Adds a banner to the top of each generated chunk.",
4-
"version": "0.6.0",
4+
"version": "0.6.1",
55
"author": "chengpeiquan <[email protected]>",
66
"license": "MIT",
77
"homepage": "https://github.com/chengpeiquan/vite-plugin-banner",

src/libs/formatConfig.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,11 @@ export default function formatConfig(
2525
const type: string = Object.prototype.toString.call(options)
2626

2727
// Block illegal types
28-
if (!['[object String]', '[object Object]', '[object Function]'].includes(type)) {
28+
if (
29+
!['[object String]', '[object Object]', '[object Function]'].includes(type)
30+
) {
2931
throw new Error(
30-
'[vite-plugin-banner] The options must be a string, an object or a callback function.'
32+
'[vite-plugin-banner] The options must be a string, an object or a function.'
3133
)
3234
}
3335

test/formatConfig.test.ts

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import formatConfig from '../src/libs/formatConfig'
2+
3+
describe('formatConfig.ts', () => {
4+
test('Illegal options type', () => {
5+
expect(() => {
6+
formatConfig(undefined as any)
7+
}).toThrow(
8+
'[vite-plugin-banner] The options must be a string, an object or a function.'
9+
)
10+
})
11+
})
12+
13+
describe('formatConfig.ts', () => {
14+
test('Empty content', () => {
15+
expect(() => {
16+
formatConfig({
17+
content: '',
18+
outDir: '',
19+
})
20+
}).toThrow('[vite-plugin-banner] The banner content can not be empty.')
21+
})
22+
})
23+
24+
describe('formatConfig.ts', () => {
25+
test('Valid options type', () => {
26+
expect(
27+
formatConfig({
28+
content: 'Hello World',
29+
outDir: '',
30+
})
31+
).toStrictEqual({
32+
content: 'Hello World',
33+
outDir: '',
34+
debug: false,
35+
verify: true,
36+
})
37+
})
38+
})
39+
40+
describe('formatConfig.ts', () => {
41+
test('Illegal options type', () => {
42+
function callback(fileName: string) {
43+
return fileName.endsWith('.js')
44+
? 'This message will inject into `js` files.'
45+
: 'This message will inject into other files.'
46+
}
47+
48+
expect(() => {
49+
formatConfig(callback)
50+
}).toStrictEqual({
51+
content: expect.any(Function),
52+
outDir: '',
53+
debug: false,
54+
verify: true,
55+
})
56+
})
57+
})

test/getConfig.test.ts

-36
This file was deleted.

test/verifyBanner.test.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,16 @@ describe('verifyBanner.ts', () => {
1414

1515
describe('verifyBanner.ts', () => {
1616
test('Illegal content type', () => {
17-
expect(verifyBanner(null)).toBe('The banner content must be a string.')
17+
expect(verifyBanner(null as any)).toBe(
18+
'The banner content must be a string.'
19+
)
1820
})
1921
})
2022

2123
describe('verifyBanner.ts', () => {
2224
test('Illegal content type', () => {
23-
expect(verifyBanner(undefined)).toBe('The banner content must be a string.')
25+
expect(verifyBanner(undefined as any)).toBe(
26+
'The banner content must be a string.'
27+
)
2428
})
2529
})

0 commit comments

Comments
 (0)