Skip to content
Open
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
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"license": "MIT",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "jest"
},
"repository": {
"type": "git",
Expand All @@ -20,6 +20,7 @@
"loader-utils": "^1.1.0"
},
"devDependencies": {
"jest": "^24.1.0",
"webpack": "^2.2.1"
}
}
2 changes: 1 addition & 1 deletion src/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const { tag, prefixTag } = require('./tag-map');

function replaceTag(source, tagMap) {
Object.keys(tagMap).forEach(i => {
source = source.replace(new RegExp(`<${i}(?!-)`, 'g'), `<${tagMap[i]}`)
source = source.replace(new RegExp(`<${i}(?![-a-zA-Z])`, 'g'), `<${tagMap[i]}`)
.replace(new RegExp(`<\/${i}>`, 'g'), `<\/${tagMap[i]}>`);
})
return source;
Expand Down
24 changes: 24 additions & 0 deletions test/loader.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
const originLoader = require('../src/loader')

const baseLoaderContext = {
cacheable: () => { },
}
const normalLoader = originLoader.bind({
...baseLoaderContext,
query: '?prefix=false',
})

const prefixLoader = originLoader.bind({
...baseLoaderContext,
query: '?prefix=true',
})

test('替换该替换的标签', () => {
expect(normalLoader('<Circle></Circle>')).toBe('<i-circle></i-circle>')
expect(prefixLoader('<i-table></i-table>')).toBe('<Table></Table>')
})

test('不替换该不替换的标签', () => {
expect(normalLoader('<CircleLoading></CircleLoading>')).toBe('<CircleLoading></CircleLoading>')
expect(prefixLoader('<i-table-header></i-table-header>')).toBe('<i-table-header></i-table-header>')
})