Skip to content
This repository was archived by the owner on Jan 18, 2022. It is now read-only.

Commit c61e6d6

Browse files
committed
test: customTag option
1 parent 8ae8568 commit c61e6d6

10 files changed

+105
-16
lines changed

jest.config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ module.exports = {
22
collectCoverageFrom: ['src/**'],
33
moduleFileExtensions: ['js', 'ts', 'json'],
44
transform: {
5-
'^.+\\.ts$': '<rootDir>/node_modules/ts-jest/preprocessor.js',
5+
'^.+\\.ts$': 'ts-jest',
66
},
7-
testMatch: ['**/?(*.)spec.ts'],
7+
testMatch: ['**/*.spec.ts'],
88
testEnvironment: 'node'
99
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
"pre:docs": "cp CHANGELOG.md docs/changelog.md",
3838
":docs": "vuepress dev docs/",
3939
"post:docs": "rm docs/CHANGELOG.md",
40-
"lint": "prettier --no-semi --single-quote --write **/*.js src/*.ts **/*.vue !test/target/** !dist/**",
40+
"lint": "prettier --no-semi --single-quote --write **/*.js **/*.ts **/*.vue !test/target/** !dist/**",
4141
"release": "standard-version -a",
4242
"test": "jest"
4343
},

src/index.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,13 @@ export interface VuePluginOptions {
5858
}
5959
/**
6060
* Exclude/Include customBlocks for final build.
61-
* @default `['!*']`
61+
* @default `() => false`
6262
* @example
6363
* ```js
6464
* VuePlugin({ customBlocks: ['markdown', '!test'] })
6565
* ```
6666
*/
67-
customBlocks?: string[] | (() => boolean)
67+
customBlocks?: string[] | ((tag: string) => boolean)
6868
/**
6969
* Inject CSS in JavaScript.
7070
* @default `true`
@@ -244,12 +244,13 @@ export default function vue(opts: VuePluginOptions = {}): Plugin {
244244
)
245245
)
246246

247+
descriptors.set(filename, descriptor)
248+
247249
const scopeId =
248250
'data-v-' +
249251
(isProduction
250252
? hash(path.basename(filename) + source)
251253
: hash(filename + source))
252-
descriptors.set(filename, descriptor)
253254

254255
const styles = await Promise.all(
255256
descriptor.styles.map(async style => {

test/baseline.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ let browser: Browser | null = null
1010
beforeAll(async () => {
1111
browser = await puppeteer.launch({
1212
args: ['--no-sandbox', '--disable-setuid-sandbox'],
13-
headless: Boolean(process.env.CI),
13+
headless: Boolean(process.env.CI)
1414
})
1515
})
1616

test/forward-style-compiler-errors.spec.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
import pluginVue from '../src'
22

3-
describe("forward-style-compiler-errors", () => {
4-
it("throws", async () => {
3+
describe('forward-style-compiler-errors', () => {
4+
it('throws', async () => {
55
let plugin = pluginVue()
6-
await expect((plugin as any).transform(`
6+
await expect(
7+
(plugin as any).transform(
8+
`
79
<template>
810
<div>Hello, world</div>
911
</template>
1012
<style lang="scss">
1113
@import 'file-not-exits.scss';
1214
</style>
13-
`, 'virtual-file.vue'
15+
`,
16+
'virtual-file.vue'
1417
)
1518
).rejects.toBeInstanceOf(Error)
1619
})

test/options/custom-blocks.spec.ts

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import vue, { VuePluginOptions } from '../../src'
2+
import { pluginInline } from '../setup/plugins'
3+
import { rollup } from 'rollup'
4+
5+
describe('customBlocks', () => {
6+
async function setup(options?: Partial<VuePluginOptions>) {
7+
return rollup({
8+
input: '/entry.vue',
9+
plugins: [
10+
pluginInline(
11+
'/entry.vue',
12+
`
13+
<template>
14+
<div>Hello, world</div>
15+
</template>
16+
<custom>
17+
// My Custom Block
18+
</custom>
19+
<docs>
20+
// My Docs Block
21+
</docs>
22+
`
23+
),
24+
vue({
25+
...options,
26+
normalizer: 'vue-runtime-helpers/dist/normalize-component.mjs'
27+
})
28+
]
29+
})
30+
.then(bundle => bundle.generate({ format: 'es' }))
31+
.then(generated => generated.output[0])
32+
}
33+
34+
it('default', async () => {
35+
const { code } = await setup()
36+
37+
expect(code).not.toEqual(expect.stringContaining('My Custom Block'))
38+
expect(code).not.toEqual(expect.stringContaining('My Docs Block'))
39+
})
40+
41+
it('array of tags', async () => {
42+
const { code } = await setup({
43+
customBlocks: ['custom']
44+
})
45+
46+
expect(code).toEqual(expect.stringContaining('My Custom Block'))
47+
expect(code).not.toEqual(expect.stringContaining('My Docs Block'))
48+
})
49+
it('negative array of tags', async () => {
50+
const { code } = await setup({
51+
customBlocks: ['*', '!custom']
52+
})
53+
54+
expect(code).not.toEqual(expect.stringContaining('My Custom Block'))
55+
expect(code).toEqual(expect.stringContaining('My Docs Block'))
56+
})
57+
it('function', async () => {
58+
const { code } = await setup({
59+
customBlocks(tag) {
60+
return tag === 'custom'
61+
}
62+
})
63+
64+
expect(code).toEqual(expect.stringContaining('My Custom Block'))
65+
expect(code).not.toEqual(expect.stringContaining('My Docs Block'))
66+
})
67+
})

test/setup/plugins.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { Plugin } from 'rollup'
2+
13
const pluginBabel = require('rollup-plugin-babel')
24
const pluginNodeResolve = require('rollup-plugin-node-resolve')
35
const pluginCommonJS = require('rollup-plugin-commonjs')
@@ -6,6 +8,22 @@ const pluginMarkdown = require('rollup-plugin-md')
68
const pluginTypescript = require('rollup-plugin-typescript')
79
const pluginReplace = require('rollup-plugin-replace')
810

11+
export function pluginInline(filename: string, code: string): Plugin {
12+
return {
13+
name: 'inline',
14+
resolveId(id: string) {
15+
if (id === filename) return filename
16+
17+
return null
18+
},
19+
load(id: string) {
20+
if (id === filename) return code
21+
22+
return null
23+
}
24+
}
25+
}
26+
927
export const plugins = [
1028
pluginImage({ emitFiles: false }),
1129
pluginMarkdown(),

typings/hash-sum.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
declare module 'hash-sum' {
22
const sum: (any: string) => string
33
export = sum
4-
}
4+
}

typings/puppeteer.d.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
interface Element { }
2-
interface Node { }
3-
interface NodeListOf<TNode = Node> { }
1+
interface Element {}
2+
interface Node {}
3+
interface NodeListOf<TNode = Node> {}

typings/rollup-plugins.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,4 @@ declare module 'rollup-plugin-md' {
2222

2323
declare module 'rollup-pluginutils' {
2424
export function createFilter(a: any, b: any): (any: any) => boolean
25-
}
25+
}

0 commit comments

Comments
 (0)