Skip to content

Commit 0a8c6a7

Browse files
committed
Add e2e test for metalsmith custom plugin
1 parent e5a1c78 commit 0a8c6a7

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

Diff for: test/e2e/mock-metalsmith-custom/meta.js

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
module.exports = {
2+
"metalsmith": function (metalsmith, opts, helpers) {
3+
function customMetalsmithPlugin (files, metalsmith, done) {
4+
// Implement something really custom here.
5+
6+
var readme = files['readme.md']
7+
delete files['readme.md']
8+
files['custom/readme.md'] = readme
9+
10+
console.log(files)
11+
12+
done(null, files)
13+
}
14+
15+
metalsmith.use(customMetalsmithPlugin)
16+
}
17+
}

Diff for: test/e2e/mock-metalsmith-custom/template/readme.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Metalsmith

Diff for: test/e2e/test.js

+12-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const metadata = require('../../lib/options')
1313
const { isLocalPath, getTemplatePath } = require('../../lib/local-path')
1414

1515
const MOCK_META_JSON_PATH = path.resolve('./test/e2e/mock-meta-json')
16+
const MOCK_METALSMITH_CUSTOM = path.resolve('./test/e2e/mock-metalsmith-custom')
1617
const MOCK_TEMPLATE_REPO_PATH = path.resolve('./test/e2e/mock-template-repo')
1718
const MOCK_TEMPLATE_BUILD_PATH = path.resolve('./test/e2e/mock-template-build')
1819
const MOCK_METADATA_REPO_JS_PATH = path.resolve('./test/e2e/mock-metadata-repo-js')
@@ -120,6 +121,16 @@ describe('vue-cli', () => {
120121
})
121122
})
122123

124+
it('supports custom metalsmith plugins', done => {
125+
generate('test', MOCK_METALSMITH_CUSTOM, MOCK_TEMPLATE_BUILD_PATH, err => {
126+
if (err) done(err)
127+
128+
expect(exists(`${MOCK_TEMPLATE_BUILD_PATH}/custom/readme.md`)).to.equal(true)
129+
130+
done()
131+
})
132+
})
133+
123134
it('generate a vaild package.json with escaped author', done => {
124135
monkeyPatchInquirer(escapedAnswers)
125136
generate('test', MOCK_TEMPLATE_REPO_PATH, MOCK_TEMPLATE_BUILD_PATH, err => {
@@ -254,7 +265,7 @@ describe('vue-cli', () => {
254265
expect(getTemplatePath('../template')).to.equal(path.join(__dirname, '/../../../template'))
255266
})
256267

257-
it.only('points out the file in the error', done => {
268+
it('points out the file in the error', done => {
258269
monkeyPatchInquirer(answers)
259270
generate('test', MOCK_ERROR, MOCK_TEMPLATE_BUILD_PATH, err => {
260271
expect(err.message).to.match(/^\[readme\.md\] Parse error/)

0 commit comments

Comments
 (0)