-
-
Notifications
You must be signed in to change notification settings - Fork 529
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Concept for e2e testing using jest
- Loading branch information
1 parent
0b6fd22
commit d32b4c0
Showing
5 changed files
with
2,217 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
'use strict'; | ||
|
||
const express = require('express'); | ||
const puppeteer = require('puppeteer'); | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const http = require('http'); | ||
|
||
describe('e2e', () => { | ||
|
||
let app; | ||
let browser; | ||
let page; | ||
let server; | ||
|
||
beforeAll(async () => { | ||
app = express(); | ||
app.all('/api/*', (req, res) => { | ||
res.send({ | ||
method: req.method, | ||
protocol: req.protocol, | ||
hostname: req.hostname, | ||
path: req.path, | ||
url: req.url, | ||
query: req.query, | ||
body: req.body, | ||
headers: req.headers, | ||
}); | ||
}); | ||
server = app.listen(3000); | ||
browser = await puppeteer.launch(); | ||
page = await browser.newPage(); | ||
}); | ||
|
||
afterAll(async () => { | ||
await page.close(); | ||
await browser.close(); | ||
await server.close(); | ||
}); | ||
|
||
it('runs in chrome', async () => { | ||
await page.goto('http://localhost:3000/api/test', { | ||
waitUntil: 'networkidle0', | ||
}); | ||
const content = await page.content(); | ||
expect(content).toBeDefined(); | ||
}); | ||
|
||
it('runs in node', async () => { | ||
return new Promise((resolve) => { | ||
http.get('http://localhost:3000/api/test', (res) => { | ||
const chunks = []; | ||
res.on('data', (chunk) => { | ||
chunks.push(chunk); | ||
}); | ||
res.on('end', () => { | ||
const content = Buffer.concat(chunks).toString(); | ||
console.log(content); | ||
expect(content).toBeDefined(); | ||
resolve(); | ||
}); | ||
}) | ||
}); | ||
}); | ||
|
||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
In the before all script: | ||
|
||
generate 6 libraries | ||
- fetch (v2 & v3) | ||
- xhr (v2 & v3) | ||
- node (v2 & v3) | ||
|
||
/generated/v2/fetch | ||
/generated/v2/xhr | ||
/generated/v2/node | ||
/generated/v3/fetch | ||
/generated/v3/xhr | ||
/generated/v3/node | ||
|
||
link in 6 projects | ||
- fetch (v2 & v3) | ||
- xhr (v2 & v3) | ||
- node (v2 & v3) | ||
Note: This can be one base 'template' that copies to dirs above | ||
|
||
Compile projects | ||
|
||
Start server that serves the api echo sever. | ||
|
||
In the tests: | ||
Run e2e tests (node + puppeteer) | ||
|
||
After all tests: | ||
Close pupeteer and server! | ||
|
||
|
Oops, something went wrong.