Skip to content

Commit

Permalink
- Concept for e2e testing using jest
Browse files Browse the repository at this point in the history
  • Loading branch information
ferdikoomen committed Sep 24, 2020
1 parent 0b6fd22 commit d32b4c0
Show file tree
Hide file tree
Showing 5 changed files with 2,217 additions and 45 deletions.
2 changes: 1 addition & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module.exports = {
testRegex: '.*\\.spec\\.(ts|js)$',
testRegex: '.*\\.spec\\.(js|js)$',
testPathIgnorePatterns: [
'/node_modules/',
'<rootDir>/dist/',
Expand Down
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
"release": "rollup --config --environment NODE_ENV:production",
"start": "nest start --path ./test/server/tsconfig.json",
"start:watch": "nest start --path ./test/server/tsconfig.json --watch",
"run": "node ./test/index.js",
"test": "jest",
"test:update": "jest --updateSnapshot",
"test:watch": "jest --watch",
Expand Down Expand Up @@ -97,15 +98,18 @@
"eslint-config-prettier": "6.11.0",
"eslint-plugin-prettier": "3.1.4",
"eslint-plugin-simple-import-sort": "5.0.3",
"express": "4.17.1",
"glob": "7.1.6",
"jest": "26.4.2",
"jest-cli": "26.4.2",
"prettier": "2.1.2",
"puppeteer": "5.3.1",
"reflect-metadata": "0.1.13",
"rollup": "2.28.2",
"rollup-plugin-terser": "7.0.2",
"rollup-plugin-typescript2": "0.27.2",
"swagger-ui-express": "4.1.4",
"testcafe": "1.9.3",
"typescript": "4.0.3"
}
}
66 changes: 66 additions & 0 deletions test/index.spec.js
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();
});
})
});
});

})
31 changes: 31 additions & 0 deletions test/readme.md
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!


Loading

0 comments on commit d32b4c0

Please sign in to comment.