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

813
package-lock.json generated

File diff suppressed because it is too large Load Diff

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

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