Merge pull request #2201 from sveltejs/puppeteer

swap out nightmare for puppeteer
pull/2203/head
Rich Harris 6 years ago committed by GitHub
commit 9bfbbae666
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

811
package-lock.json generated

File diff suppressed because it is too large Load Diff

@ -67,7 +67,7 @@
"locate-character": "^2.0.5", "locate-character": "^2.0.5",
"magic-string": "^0.25.2", "magic-string": "^0.25.2",
"mocha": "^5.2.0", "mocha": "^5.2.0",
"nightmare": "^3.0.1", "puppeteer": "^1.13.0",
"rollup": "^1.1.2", "rollup": "^1.1.2",
"rollup-plugin-commonjs": "^9.1.0", "rollup-plugin-commonjs": "^9.1.0",
"rollup-plugin-json": "^3.0.0", "rollup-plugin-json": "^3.0.0",

@ -3,7 +3,7 @@ import * as path from 'path';
import * as http from 'http'; import * as http from 'http';
import { rollup } from 'rollup'; import { rollup } from 'rollup';
import * as virtual from 'rollup-plugin-virtual'; import * as virtual from 'rollup-plugin-virtual';
import * as Nightmare from 'nightmare'; import * as puppeteer from 'puppeteer';
import { addLineNumbers, loadConfig, loadSvelte } from "../helpers.js"; import { addLineNumbers, loadConfig, loadSvelte } from "../helpers.js";
const page = ` const page = `
@ -20,30 +20,36 @@ describe('custom-elements', function() {
let svelte; let svelte;
let server; let server;
let bundle; let browser;
let code;
before(() => {
svelte = loadSvelte();
function create_server() {
return new Promise((fulfil) => { return new Promise((fulfil) => {
server = http.createServer((req, res) => { const server = http.createServer((req, res) => {
if (req.url === '/') { if (req.url === '/') {
res.end(page); res.end(page);
} }
if (req.url === '/bundle.js') { if (req.url === '/bundle.js') {
res.end(bundle); res.end(code);
} }
}); });
server.listen('6789', () => { server.listen('6789', () => {
fulfil(); fulfil(server);
}); });
}); });
}
before(async () => {
svelte = loadSvelte();
server = await create_server();
browser = await puppeteer.launch();
}); });
after(() => { after(async () => {
server.close(); server.close();
await browser.close();
}); });
fs.readdirSync('test/custom-elements/samples').forEach(dir => { fs.readdirSync('test/custom-elements/samples').forEach(dir => {
@ -54,10 +60,10 @@ describe('custom-elements', function() {
const internal = path.resolve('internal.mjs'); const internal = path.resolve('internal.mjs');
const index = path.resolve('index.mjs'); const index = path.resolve('index.mjs');
(solo ? it.only : skip ? it.skip : it)(dir, () => { (solo ? it.only : skip ? it.skip : it)(dir, async () => {
const config = loadConfig(`./custom-elements/samples/${dir}/_config.js`); const config = loadConfig(`./custom-elements/samples/${dir}/_config.js`);
return rollup({ const bundle = await rollup({
input: `test/custom-elements/samples/${dir}/test.js`, input: `test/custom-elements/samples/${dir}/test.js`,
plugins: [ plugins: [
{ {
@ -87,35 +93,26 @@ describe('custom-elements', function() {
assert assert
}) })
] ]
}) });
.then(bundle => bundle.generate({ format: 'iife', name: 'test' }))
.then(result => {
bundle = result.output[0].code;
const nightmare = new Nightmare({ show: false }); const result = await bundle.generate({ format: 'iife', name: 'test' });
code = result.output[0].code;
nightmare.on('console', (type, ...args) => { const page = await browser.newPage();
console[type](...args);
});
return nightmare page.on('console', (type, ...args) => {
.goto('http://localhost:6789') console[type](...args);
.evaluate(() => {
return test(document.querySelector('main'));
})
.then(result => {
if (result) console.log(result);
return nightmare.end();
})
.catch(message => {
console.log(addLineNumbers(bundle));
return nightmare.end().then(() => {
throw new Error(message);
});
});
}); });
try {
await page.goto('http://localhost:6789');
const result = await page.evaluate(() => test(document.querySelector('main')));
if (result) console.log(result);
} catch (err) {
console.log(addLineNumbers(code));
throw err;
}
}); });
}); });
}); });

Loading…
Cancel
Save