Skip to content

Commit a5cd62f

Browse files
committed
- E2E test working, failing on node, but support will be build soon
1 parent 75c9ef3 commit a5cd62f

23 files changed

+106
-235
lines changed

jest.config.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ module.exports = {
1616
testEnvironment: 'node',
1717
testMatch: [
1818
'<rootDir>/test/e2e/v2.fetch.spec.js',
19-
// '<rootDir>/test/e2e/v2.xhr.spec.js',
20-
// '<rootDir>/test/e2e/v2.node.spec.js',
21-
// '<rootDir>/test/e2e/v3.fetch.spec.js',
22-
// '<rootDir>/test/e2e/v3.xhr.spec.js',
23-
// '<rootDir>/test/e2e/v3.node.spec.js',
19+
'<rootDir>/test/e2e/v2.xhr.spec.js',
20+
'<rootDir>/test/e2e/v2.node.spec.js',
21+
'<rootDir>/test/e2e/v3.fetch.spec.js',
22+
'<rootDir>/test/e2e/v3.xhr.spec.js',
23+
'<rootDir>/test/e2e/v3.node.spec.js',
2424
],
2525
},
2626
],

package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,7 @@
3939
},
4040
"files": [
4141
"bin/index.js",
42-
"dist/index.js",
43-
"src/templates/**/*.ts"
42+
"dist/index.js"
4443
],
4544
"scripts": {
4645
"clean": "rimraf ./dist ./test/generated ./test/e2e/generated ./samples/generated ./coverage ./node_modules/.cache",
@@ -61,7 +60,7 @@
6160
"prettier:fix": "prettier \"./src/**/*.ts\" \"./bin/index.js\" --write",
6261
"prepublish": "yarn run clean && yarn run release",
6362
"codecov": "codecov --token=66c30c23-8954-4892-bef9-fbaed0a2e42b",
64-
"aap": "node ./test/e2e/index.js"
63+
"aap": "node test/e2e/index.js"
6564
},
6665
"dependencies": {
6766
"camelcase": "6.0.0",
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
import('./index.js').then(module => {
2-
window.test = module;
2+
window.api = module;
33
});

test/e2e/index.js

Lines changed: 0 additions & 4 deletions
This file was deleted.

test/e2e/scripts/browser.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ let browser;
66
let page
77

88
async function start() {
9+
// This starts the a new puppeteer browser (Chrome)
10+
// and load the localhost page, this page will load the
11+
// javascript modules (see server.js for more info)
912
browser = await puppeteer.launch();
1013
page = await browser.newPage();
1114
await page.goto(`http://localhost:3000/`, {

test/e2e/scripts/compile.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const path = require('path');
55
const os = require('os');
66

77
function compile(version, client) {
8-
const baseDir = `./test/e2e/generated/${version}/${client}/js/api/`;
8+
const baseDir = `./test/e2e/generated/${version}/${client}/`;
99
const tsconfig = {
1010
compilerOptions: {
1111
target: 'es6',
@@ -14,11 +14,15 @@ function compile(version, client) {
1414
},
1515
include: ['./index.ts'],
1616
};
17+
18+
// Compile files to JavaScript (ES6 modules)
1719
const configFile = ts.parseConfigFileTextToJson('tsconfig.json', JSON.stringify(tsconfig));
1820
const configFileResult = ts.parseJsonConfigFileContent(configFile.config, ts.sys, path.resolve(process.cwd(), baseDir), undefined, 'tsconfig.json');
1921
const compilerHost = ts.createCompilerHost(configFileResult.options);
2022
const compiler = ts.createProgram(configFileResult.fileNames, configFileResult.options, compilerHost);
2123
const result = compiler.emit();
24+
25+
// Show errors or warnings (if any)
2226
const diagnostics = ts.getPreEmitDiagnostics(compiler).concat(result.diagnostics);
2327
if (diagnostics.length) {
2428
console.log(ts.formatDiagnosticsWithColorAndContext(diagnostics, {

test/e2e/scripts/copy.js

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,12 @@
11
'use strict';
22

33
const fs = require('fs');
4-
const path = require('path');
5-
const glob = require('glob');
64

75
async function copy(version, client) {
8-
const input = path.resolve('./test/e2e/test/');
9-
const output = path.resolve(`./test/e2e/generated/${version}/${client}/js`);
10-
const files = glob.sync('*.js', { cwd: input });
11-
for (let file of files) {
12-
fs.copyFileSync(
13-
path.resolve(input, file),
14-
path.resolve(output, file)
15-
);
16-
}
6+
fs.copyFileSync(
7+
'./test/e2e/assets/script.js',
8+
`./test/e2e/generated/${version}/${client}/script.js`,
9+
);
1710
}
1811

1912
module.exports = copy;

test/e2e/scripts/generate.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const OpenAPI = require('../../../dist');
55
async function generate(version, client) {
66
await OpenAPI.generate({
77
input: `./test/spec/${version}.json`,
8-
output: `./test/e2e/generated/${version}/${client}/js/api/`,
8+
output: `./test/e2e/generated/${version}/${client}/`,
99
httpClient: client,
1010
useOptions: false,
1111
useUnionTypes: false,

test/e2e/scripts/server.js

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,34 @@ async function start(version, client) {
99
return new Promise(resolve => {
1010
app = express();
1111

12-
app.use(express.static(`./test/e2e/generated/${version}/${client}`, {
12+
// Serve the JavaScript files from the specific folder, since we are using browser
13+
// based ES6 modules, this also means that we can just request the js/index.js file
14+
// and all other relative paths are resolved from that file.
15+
app.use('/js', express.static(`./test/e2e/generated/${version}/${client}/`, {
1316
extensions: ['', 'js'],
1417
index: 'index.js'
1518
}));
1619

20+
// When we request the index then we can just return the script loader.
21+
// This file is copied from test/e2e/assets/script.js to the output directory
22+
// of the specific version and client.
1723
app.get('/', (req, res) => {
18-
res.send('<script src="public/script.js"></script>');
24+
res.send('<script src="js/script.js"></script>');
1925
});
2026

27+
const aap = (obj) => {
28+
const a = {};
29+
for (const key in obj) {
30+
a[key] = obj[key];
31+
}
32+
return a;
33+
}
34+
35+
// Register an 'echo' server that just returns all data from the API calls.
36+
// Although this might not be a 'correct' response, we can use this to test
37+
// the majority of API calls.
2138
app.all('/base/api/*', (req, res) => {
22-
res.send({
39+
res.json({
2340
method: req.method,
2441
protocol: req.protocol,
2542
hostname: req.hostname,

test/e2e/test/index.js

Lines changed: 0 additions & 17 deletions
This file was deleted.

0 commit comments

Comments
 (0)