Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/10 typescript migration #30

Merged
merged 23 commits into from
Apr 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,23 @@
"es2021": true,
"jest": true
},
"extends": ["eslint:recommended", "plugin:jest-playwright/recommended", "prettier"],
"extends": [
"prettier",
"plugin:@typescript-eslint/recommended",
"prettier/@typescript-eslint",
"plugin:prettier/recommended"
],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 12
},
"plugins": ["@typescript-eslint","plugin:jest-playwright/recommended", "prettier"],
"rules": {
"indent": ["error", 2],
"linebreak-style": ["error", "unix"],
"quotes": ["error", "single"],
"semi": ["error", "always"],
"eol-last": ["error", "always"]
}
},
"ignorePatterns": "dist/**"
}
17 changes: 0 additions & 17 deletions .gcloudignore

This file was deleted.

2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
node_modules
dist

35 changes: 15 additions & 20 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,37 +4,32 @@
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen",
"name": "nodemon",
"program": "${workspaceFolder}/app.js",
"request": "launch",
"restart": true,
"runtimeExecutable": "nodemon",
"skipFiles": ["<node_internals>/**"],
"type": "pwa-node"
},
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"skipFiles": ["<node_internals>/**"],
"program": "${workspaceFolder}\\app.js"
},
{
"name": "Debug Jest Tests",
"type": "node",
"request": "launch",
"runtimeArgs": [
"--inspect-brk",
"${workspaceRoot}/node_modules/jest/bin/jest.js",
//"<filename>", // uncomment in case only one test should be started
// "<testfile>", // uncomment in case only one test should be started
"--runInBand"
],
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen",
"port": 9229
}
},
{
"name": "Debug e2e Test File",
"type": "node",
"request": "launch",
"program": "${workspaceFolder}/node_modules/.bin/jest",
"args": ["${fileBasenameNoExtension}", "--config", "jest.e2e.config.js", "script"],
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen",
"disableOptimisticBPs": true,
"windows": {
"program": "${workspaceFolder}/node_modules/jest/bin/jest"
}
},
]
}
14 changes: 4 additions & 10 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
{
"liveServer.settings.port": 5501,
"eslint.debug": true,
"eslint.format.enable": true,
"editor.formatOnSave": true,
"[javascript]": {
"editor.formatOnSave": true
},
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
},
"eslint.alwaysShowStatus": true,
"files.autoSave": "onFocusChange"
"editor.detectIndentation": false,
"typescript.validate.enable": false,
"editor.formatOnSave": true,
"editor.codeActionsOnSave": { "source.fixAll": true }
}
44 changes: 0 additions & 44 deletions app.js

This file was deleted.

1 change: 0 additions & 1 deletion app.yaml

This file was deleted.

93 changes: 0 additions & 93 deletions bin/www

This file was deleted.

56 changes: 56 additions & 0 deletions build.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/**
* Remove old files, copy front-end ones.
*/

import fs from 'fs-extra';
import Logger from 'jet-logger';
import childProcess from 'child_process';

// Setup logger
const logger = new Logger();
logger.timestamp = false;

(async () => {
try {
// Remove current build
await remove('./dist/');
// Copy front-end files
await copy('./src/public/stylesheets', './dist/public/stylesheets');
// Copy only htmls from views folder
await exec('mkdir dist/views; cp -r src/views/*.html dist/views', './')
// Copy back-end files
await exec('tsc', './');
} catch (err) {
logger.err(err);
}
})();

function remove(loc: string): Promise<void> {
return new Promise((res, rej) => {
return fs.remove(loc, (err) => {
return !!err ? rej(err) : res();
});
});
}

function copy(src: string, dest: string): Promise<void> {
return new Promise((res, rej) => {
return fs.copy(src, dest, (err) => {
return !!err ? rej(err) : res();
});
});
}

function exec(cmd: string, loc: string): Promise<void> {
return new Promise((res, rej) => {
return childProcess.exec(cmd, { cwd: loc }, (err, stdout, stderr) => {
if (!!stdout) {
logger.info(stdout);
}
if (!!stderr) {
logger.warn(stderr);
}
return !!err ? rej(err) : res();
});
});
}
26 changes: 26 additions & 0 deletions e2eEnvironment.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
const PlaywrightEnvironment = require('jest-playwright-preset/lib/PlaywrightEnvironment').default;

class e2eEnvironment extends PlaywrightEnvironment {
async setup() {
await super.setup();
// Your setup
}

async teardown() {
// Your teardown
await super.teardown();
}

async handleTestEvent(event) {
if (event.name === 'test_done' && event.test.errors.length > 0) {
const parentName = event.test.parent.name.replace(/\W/g, '-');
const specName = event.test.name.replace(/\W/g, '-');

await this.global.page.screenshot({
path: `screenshots/${parentName}/${specName}.png`,
});
}
}
}

module.exports = e2eEnvironment;
12 changes: 12 additions & 0 deletions jest-playwright.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// jest playwright options: https://github.com/playwright-community/jest-playwright#options
module.exports = {
// https://playwright.dev/docs/api/class-browser/#browsernewcontextoptions
contextOptions: {
locale: 'de-DE',
},
// https://playwright.dev/docs/api/class-browsertype/#browsertypelaunchoptions
launchOptions: {
headless: true,
devtools: false,
},
};
6 changes: 6 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
preset: 'ts-jest',
testEnvironment: 'jsdom',
testMatch: ['**/+(*.)+(spec).+(ts)'],
transformIgnorePatterns: ['node_modules', 'dist'],
};
8 changes: 7 additions & 1 deletion jest.e2e.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
module.exports = {
preset: 'jest-playwright-preset',
testMatch: ['**/__tests__/**/*.+(ts|js)', '**/?(*.)+(e2e.)+(spec|test).+(ts|js)'],
testEnvironment: './e2eEnvironment.js',
testMatch: ['**/*e2e.spec.ts'],
transform: {
'^.+\\.(ts)$': 'ts-jest',
},
transformIgnorePatterns: ['node_modules', 'dist'],
testTimeout: 900000,
};
Loading