Skip to content

Commit

Permalink
- Working on e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ferdikoomen committed Sep 25, 2020
1 parent d32b4c0 commit 1785e3e
Show file tree
Hide file tree
Showing 36 changed files with 591 additions and 5,118 deletions.
6 changes: 3 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ junit.xml
*.iml
dist
coverage
samples/dist
test/generated
test/e2e/generated
samples/generated
samples/swagger-codegen-cli-v2.jar
samples/swagger-codegen-cli-v3.jar
test/generator/dist
test/server/dist
2 changes: 1 addition & 1 deletion bin/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ if (OpenAPI) {
exportCore: JSON.parse(program.exportCore) === true,
exportServices: JSON.parse(program.exportServices) === true,
exportModels: JSON.parse(program.exportModels) === true,
exportSchemas: JSON.parse(program.exportSchemas) === true,
exportSchemas: JSON.parse(program.exportSchemas) === true
})
.then(() => {
process.exit(0);
Expand Down
40 changes: 26 additions & 14 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,29 @@
module.exports = {
testRegex: '.*\\.spec\\.(js|js)$',
testPathIgnorePatterns: [
'/node_modules/',
'<rootDir>/dist/',
'<rootDir>/samples/',
],
testEnvironment: 'node',
moduleNameMapper: {
'\\.hbs$': '<rootDir>/src/templates/__mocks__/index.js',
},
collectCoverageFrom: [
'src/**/*.ts',
'!src/**/*.d.ts',
'!**/node_modules/**',
projects: [
{
displayName: 'UNIT',
testEnvironment: 'node',
testMatch: [
'<rootDir>/src/**/*.spec.ts',
'<rootDir>/test/**/*.spec.js',
],
moduleNameMapper: {
'\\.hbs$': '<rootDir>/src/templates/__mocks__/index.js',
},
collectCoverageFrom: [
'src/**/*.ts',
'!src/**/*.d.ts',
],
},
{
displayName: 'E2E',
testEnvironment: 'node',
testMatch: [
'<rootDir>/test/e2e/index.js',
],
globals: {
URL: 'http://localhost:3000',
},
},
],
};
23 changes: 6 additions & 17 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,18 @@
"src/templates/**/*.ts"
],
"scripts": {
"clean": "rimraf ./dist ./test/generator/dist ./test/server/dist ./coverage ./samples/dist ./node_modules/.cache",
"clean": "rimraf ./dist ./test/generated ./test/e2e/generated ./samples/generated ./coverage ./node_modules/.cache",
"build": "rollup --config --environment NODE_ENV:development",
"build:watch": "rollup --config --environment NODE_ENV:development --watch",
"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",
"test:coverage": "jest --coverage",
"test": "jest --selectProjects UNIT",
"test:update": "jest --selectProjects UNIT --updateSnapshot",
"test:watch": "jest --selectProjects UNIT --watch",
"test:coverage": "jest --selectProjects UNIT --coverage",
"test:e2e": "jest --selectProjects E2E",
"eslint": "eslint \"./src/**/*.ts\" \"./test/**/*.ts\" \"./bin/index.js\"",
"eslint:fix": "eslint \"./src/**/*.ts\" \"./test/**/*.ts\" \"./bin/index.js\" --fix",
"prettier": "prettier \"./src/**/*.ts\" \"./test/**/*.ts\" \"./bin/index.js\" --check",
Expand All @@ -74,13 +75,6 @@
"@babel/core": "7.11.6",
"@babel/preset-env": "7.11.5",
"@babel/preset-typescript": "7.10.4",
"@nestjs/cli": "7.5.1",
"@nestjs/common": "7.4.4",
"@nestjs/core": "7.4.4",
"@nestjs/platform-express": "7.4.4",
"@nestjs/schematics": "7.1.2",
"@nestjs/swagger": "4.6.1",
"@nestjs/testing": "7.4.4",
"@rollup/plugin-commonjs": "15.1.0",
"@rollup/plugin-node-resolve": "9.0.0",
"@types/express": "4.17.8",
Expand All @@ -91,8 +85,6 @@
"@types/rimraf": "3.0.0",
"@typescript-eslint/eslint-plugin": "4.2.0",
"@typescript-eslint/parser": "4.2.0",
"class-transformer": "0.3.1",
"class-validator": "0.12.2",
"codecov": "3.7.2",
"eslint": "7.9.0",
"eslint-config-prettier": "6.11.0",
Expand All @@ -104,12 +96,9 @@
"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"
}
}
3 changes: 1 addition & 2 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ const fs = require('fs');
const pkg = require('./package.json');
const external = Object.keys(pkg.dependencies);


/**
* Custom plugin to parse handlebar imports and precompile
* the template on the fly. This reduces runtime by about
Expand Down Expand Up @@ -56,7 +55,7 @@ const getPlugins = () => {
return [...plugins, terser()];
}

export default {
module.exports = {
input: './src/index.ts',
output: {
file: './dist/index.js',
Expand Down
24 changes: 12 additions & 12 deletions samples/codegen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@ rm -rf dist
rm swagger-codegen-cli-v2.jar
rm swagger-codegen-cli-v3.jar

#curl https://repo1.maven.org/maven2/io/swagger/swagger-codegen-cli/2.4.15/swagger-codegen-cli-2.4.15.jar -o swagger-codegen-cli-v2.jar
#curl https://repo1.maven.org/maven2/io/swagger/codegen/v3/swagger-codegen-cli/3.0.21/swagger-codegen-cli-3.0.21.jar -o swagger-codegen-cli-v3.jar
curl https://repo1.maven.org/maven2/io/swagger/swagger-codegen-cli/2.4.15/swagger-codegen-cli-2.4.15.jar -o swagger-codegen-cli-v2.jar
curl https://repo1.maven.org/maven2/io/swagger/codegen/v3/swagger-codegen-cli/3.0.21/swagger-codegen-cli-3.0.21.jar -o swagger-codegen-cli-v3.jar

#java -jar ./swagger-codegen-cli-v2.jar generate -i spec/v2.json -l typescript-aurelia -o dist/v2/typescript-aurelia/
#java -jar ./swagger-codegen-cli-v2.jar generate -i spec/v2.json -l typescript-angular -o dist/v2/typescript-angular/
#java -jar ./swagger-codegen-cli-v2.jar generate -i spec/v2.json -l typescript-inversify -o dist/v2/typescript-inversify/
#java -jar ./swagger-codegen-cli-v2.jar generate -i spec/v2.json -l typescript-fetch -o dist/v2/typescript-fetch/
#java -jar ./swagger-codegen-cli-v2.jar generate -i spec/v2.json -l typescript-jquery -o dist/v2/typescript-jquery/
#java -jar ./swagger-codegen-cli-v2.jar generate -i spec/v2.json -l typescript-node -o dist/v2/typescript-node/
java -jar ./swagger-codegen-cli-v2.jar generate -i spec/v2.json -l typescript-aurelia -o generated/v2/typescript-aurelia/
java -jar ./swagger-codegen-cli-v2.jar generate -i spec/v2.json -l typescript-angular -o generated/v2/typescript-angular/
java -jar ./swagger-codegen-cli-v2.jar generate -i spec/v2.json -l typescript-inversify -o generated/v2/typescript-inversify/
java -jar ./swagger-codegen-cli-v2.jar generate -i spec/v2.json -l typescript-fetch -o generated/v2/typescript-fetch/
java -jar ./swagger-codegen-cli-v2.jar generate -i spec/v2.json -l typescript-jquery -o generated/v2/typescript-jquery/
java -jar ./swagger-codegen-cli-v2.jar generate -i spec/v2.json -l typescript-node -o generated/v2/typescript-node/

#java -jar ./swagger-codegen-cli-v3.jar generate -i spec/v3.json -l typescript-angular -o dist/v3/typescript-angular/
#java -jar ./swagger-codegen-cli-v3.jar generate -i spec/v3.json -l typescript-fetch -o dist/v3/typescript-fetch/
java -jar ./swagger-codegen-cli-v3.jar generate -i spec/v3.json -l typescript-angular -o generated/v3/typescript-angular/
java -jar ./swagger-codegen-cli-v3.jar generate -i spec/v3.json -l typescript-fetch -o generated/v3/typescript-fetch/

node ../bin/index.js --input spec/v2.json --output dist/v2/openapi-typescript-codegen/
node ../bin/index.js --input spec/v3.json --output dist/v3/openapi-typescript-codegen/
node ../bin/index.js --input spec/v2.json --output generated/v2/openapi-typescript-codegen/
node ../bin/index.js --input spec/v3.json --output generated/v3/openapi-typescript-codegen/
8 changes: 4 additions & 4 deletions src/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,31 @@ describe('index', () => {
it('parses v2 without issues', async () => {
await OpenAPI.generate({
input: './test/spec/v3.json',
output: './temp/v3/',
output: './generated/v3/',
write: false,
});
});

it('parses v3 without issues', async () => {
await OpenAPI.generate({
input: './test/spec/v3.json',
output: './temp/v3/',
output: './generated/v3/',
write: false,
});
});

it('downloads and parses v2 without issues', async () => {
await OpenAPI.generate({
input: 'https://raw.githubusercontent.com/ferdikoomen/openapi-typescript-codegen/master/test/spec/v2.json',
output: './temp/v2-downloaded/',
output: './generated/v2-downloaded/',
write: false,
});
});

it('downloads and parses v3 without issues', async () => {
await OpenAPI.generate({
input: 'https://raw.githubusercontent.com/ferdikoomen/openapi-typescript-codegen/master/test/spec/v3.json',
output: './temp/v3-downloaded/',
output: './generated/v3-downloaded/',
write: false,
});
});
Expand Down
Loading

0 comments on commit 1785e3e

Please sign in to comment.