Skip to content

Commit d184638

Browse files
xsbchenyyx990803
authored andcommitted
test: strip ansi chars in puppeteer test url (#1031)
fix "Protocol error (Page.navigate): Cannot navigate to invalid URL undefined" error when running test in vscode terminal(zsh)
1 parent b501dd5 commit d184638

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

packages/@vue/cli-test-utils/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
},
2323
"dependencies": {
2424
"execa": "^0.8.0",
25-
"puppeteer": "^1.0.0"
25+
"puppeteer": "^1.0.0",
26+
"strip-ansi": "^3.0.0"
2627
}
2728
}

packages/@vue/cli-test-utils/serveWithPuppeteer.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
const stripAnsi = require('strip-ansi')
12
const launchPuppeteer = require('./launchPuppeteer')
23

34
module.exports = async function serveWithPuppeteer (serve, test) {
@@ -36,8 +37,13 @@ module.exports = async function serveWithPuppeteer (serve, test) {
3637
const urlMatch = data.match(/http:\/\/[^/]+\//)
3738
if (urlMatch && isFirstMatch) {
3839
isFirstMatch = false
40+
let url = urlMatch[0]
41+
42+
// fix "Protocol error (Page.navigate): Cannot navigate to invalid URL undefined" error
43+
// when running test in vscode terminal(zsh)
44+
url = stripAnsi(url)
45+
3946
// start browser
40-
const url = urlMatch[0]
4147
const { page, browser } = await launchPuppeteer(url)
4248
activeBrowser = browser
4349

0 commit comments

Comments
 (0)