Skip to content

Commit

Permalink
make tests work on appveyor
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Jan 7, 2018
1 parent 7db2911 commit 91b2622
Show file tree
Hide file tree
Showing 10 changed files with 63 additions and 36 deletions.
1 change: 1 addition & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ install:
- yarn

test_script:
- git --version
- node --version
- yarn --version
- yarn test
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@
"lint-staged": "^6.0.0",
"memfs": "^2.6.0",
"puppeteer": "^0.13.0",
"yorkie": "^1.0.1"
"yorkie": "^1.0.2"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ test('should work', async () => {
expect(hook).toMatch('#yorkie')
await write('src/main.js', updatedMain)
// nvm doesn't like PREFIX env
delete process.env.PREFIX
if (process.platform === 'darwin') {
delete process.env.PREFIX
}
await run('git add -A')
await run('git commit -m save')
// should be linted on commit
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ jest.setTimeout(20000)
const create = require('@vue/cli-test-utils/createTestProject')

test('should work', async () => {
const { run } = await create('unit-mocha-webpack', {
const project = await create('unit-mocha-webpack', {
plugins: {
'@vue/cli-plugin-babel': {},
'@vue/cli-plugin-unit-mocha-webpack': {
assertionLibrary: 'chai'
}
}
})
await run(`vue-cli-service test`)
await project.run(`vue-cli-service test`)
})
13 changes: 6 additions & 7 deletions packages/@vue/cli-service/lib/__tests__/serve.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
jest.setTimeout(20000)
jest.setTimeout(30000)

const { defaults } = require('@vue/cli/lib/options')
const create = require('@vue/cli-test-utils/createTestProject')
Expand All @@ -9,16 +9,15 @@ const sleep = n => new Promise(resolve => setTimeout(resolve, n))
test('serve', async () => {
const project = await create('e2e-serve', defaults)

await serve(project, async ({ nextUpdate, assertText }) => {
await serve(project, async ({ nextUpdate, getText }) => {
const msg = `Welcome to Your Vue.js App`
await assertText('h1', msg)
expect(await getText('h1')).toMatch(msg)

// test hot reload
const file = await project.read(`src/App.vue`)
await project.write(`src/App.vue`, file.replace(msg, `Updated`))

project.write(`src/App.vue`, file.replace(msg, `Updated`))
await nextUpdate() // wait for child stdout update signal
await sleep(process.env.CI ? 3000 : 500) // give the client time to update
await assertText('h1', `Updated`)
await sleep(1000) // give the client time to update
expect(await getText('h1')).toMatch(`Updated`)
})
})
31 changes: 25 additions & 6 deletions packages/@vue/cli-service/lib/commands/serve.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,7 @@ module.exports = (api, options) => {
)

if (!isProduction) {
// inject dev/hot client
addDevClientToEntry(webpackConfig, [
const devClients = [
// dev server client
`webpack-dev-server/client/?${urls.localUrlForBrowser}`,
// hmr client
Expand All @@ -71,12 +70,19 @@ module.exports = (api, options) => {
: 'webpack/hot/dev-server'
// TODO custom overlay client
// `@vue/cli-overlay/dist/client`
])
]
if (process.env.APPVEYOR) {
devClients.push(`webpack/hot/poll?500`)
}
// inject dev/hot client
addDevClientToEntry(webpackConfig, devClients)
}

const compiler = webpack(webpackConfig)

compiler.apply(new webpack.ProgressPlugin())
if (!process.env.VUE_CLI_TEST) {
compiler.apply(new webpack.ProgressPlugin())
}

// log instructions & open browser on first compilation complete
let isFirstCompile = true
Expand Down Expand Up @@ -129,7 +135,7 @@ module.exports = (api, options) => {
watchContentBase: !isProduction,
hot: !isProduction,
quiet: true,
compress: true,
compress: isProduction,
publicPath: '/',
overlay: isProduction // TODO disable this
? false
Expand All @@ -154,11 +160,24 @@ module.exports = (api, options) => {
;['SIGINT', 'SIGTERM'].forEach(signal => {
process.on(signal, () => {
server.close(() => {
process.exit()
process.exit(0)
})
})
})

// on appveyor, killing the process with SIGTERM causes execa to
// throw error
if (process.env.VUE_CLI_TEST) {
process.stdin.on('data', data => {
if (data.toString() === 'close') {
console.log('got close signal!')
server.close(() => {
process.exit(0)
})
}
})
}

server.listen(port, host, err => {
if (err) {
return error(err)
Expand Down
2 changes: 1 addition & 1 deletion packages/@vue/cli-service/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
"webpack-chain": "^4.5.0",
"webpack-dev-server": "^2.10.0",
"webpack-merge": "^4.1.1",
"yorkie": "^1.0.1"
"yorkie": "^1.0.2"
},
"devDependencies": {
"vue": "^2.5.13"
Expand Down
12 changes: 6 additions & 6 deletions packages/@vue/cli-test-utils/createTestProject.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ module.exports = function createTestProject (name, config, cwd) {
}

const run = (command, args) => {
if (!args) { [command, ...args] = command.split(/\s+/) }
const child = execa(command, args, { cwd: projectRoot })
child.then(({ code, stderr }) => {
if (code !== 0 && stderr) console.error(stderr)
})
return child
[command, ...args] = command.split(/\s+/)
if (command === 'vue-cli-service') {
// appveyor has problem with paths sometimes
command = require.resolve('@vue/cli-service/bin/vue-cli-service')
}
return execa(command, args, { cwd: projectRoot })
}

const cliBinPath = require.resolve('@vue/cli/bin/vue')
Expand Down
20 changes: 11 additions & 9 deletions packages/@vue/cli-test-utils/serveWithPuppeteer.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ module.exports = async function serveWithPuppeteer (
})
}

return new Promise((resolve, reject) => {
await new Promise((resolve, reject) => {
child = project.run('vue-cli-service serve')

let isFirstMatch = true
Expand All @@ -33,25 +33,27 @@ module.exports = async function serveWithPuppeteer (
const url = urlMatch[0]
await page.goto(url)

const assertText = async (selector, text) => {
const value = await page.evaluate(() => {
return document.querySelector('h1').textContent
})
expect(value).toMatch(text)
const getText = selector => {
return page.evaluate(selector => {
return document.querySelector(selector).textContent
}, selector)
}

await testFn({
browser,
page,
url,
nextUpdate,
assertText
getText
})

await browser.close()
browser = null
child.kill()
// on appveyor, the spawned server process doesn't exit
// and causes the build to hang.
child.stdin.write('close')
child = null
// kill(child.pid)
resolve()
} else if (data.toString().match(/App updated/)) {
if (notifyUpdate) {
Expand All @@ -63,7 +65,7 @@ module.exports = async function serveWithPuppeteer (
await browser.close()
}
if (child) {
child.kill()
child.stdin.write('close')
}
reject(err)
}
Expand Down
10 changes: 7 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8774,6 +8774,10 @@ tr46@^1.0.0:
dependencies:
punycode "^2.1.0"

tree-kill@^1.2.0:
version "1.2.0"
resolved "https://registry.yarnpkg.com/tree-kill/-/tree-kill-1.2.0.tgz#5846786237b4239014f05db156b643212d4c6f36"

trim-newlines@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/trim-newlines/-/trim-newlines-1.0.0.tgz#5887966bb582a4503a41eb524f7d35011815a613"
Expand Down Expand Up @@ -9618,9 +9622,9 @@ yauzl@^2.4.2:
buffer-crc32 "~0.2.3"
fd-slicer "~1.0.1"

yorkie@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/yorkie/-/yorkie-1.0.1.tgz#7bbd6e6c7dba8f637dea82fdb695c7c18c570002"
yorkie@^1.0.2:
version "1.0.2"
resolved "https://registry.yarnpkg.com/yorkie/-/yorkie-1.0.2.tgz#910f47a06f8eab05e99e73080ebce1bc9d55c3dd"
dependencies:
execa "^0.8.0"
is-ci "^1.0.10"
Expand Down

0 comments on commit 91b2622

Please sign in to comment.