website: add support for JS/TS unit testing
Change-Id: I8bb35b7183c07c44c5e5da8dc2f2c15cc38ea64b Reviewed-on: https://go-review.googlesource.com/c/website/+/377734 Run-TryBot: Jamal Carvalho <jamal@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Alex Rakoczy <alex@golang.org> Trust: Jamal Carvalho <jamalcarvalho@google.com>
This commit is contained in:
Родитель
60e69eecf2
Коммит
6f4aa0ee4c
|
@ -1,7 +1,7 @@
|
|||
root: true
|
||||
extends: google
|
||||
parserOptions:
|
||||
ecmaVersion: 6
|
||||
ecmaVersion: 2018
|
||||
rules:
|
||||
require-jsdoc: 'off'
|
||||
indent: 'off'
|
||||
|
|
|
@ -53,6 +53,13 @@ Reference .ts files in html templates as module code.
|
|||
|
||||
`<script type="module" src="/ts/filename.ts">`
|
||||
|
||||
Write unit tests for TypeScript code using the [jest](https://jestjs.io/)
|
||||
testing framework.
|
||||
|
||||
### Run Jest
|
||||
|
||||
./npx jest [TestPathPattern]
|
||||
|
||||
## Deploying
|
||||
|
||||
Each time a CL is reviewed and submitted, the code is deployed to App Engine.
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
/**
|
||||
* @license
|
||||
* Copyright 2022 The Go Authors. All rights reserved.
|
||||
* Use of this source code is governed by a BSD-style
|
||||
* license that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
const {transform} = require('esbuild');
|
||||
|
||||
exports.createTransformer = () => ({
|
||||
canInstrument: true,
|
||||
processAsync: async (source) => {
|
||||
const result = await transform(source, {
|
||||
loader: 'ts',
|
||||
});
|
||||
if (result.warnings.length) {
|
||||
result.warnings.forEach(m => {
|
||||
console.warn(m);
|
||||
});
|
||||
}
|
||||
return {
|
||||
code: result.code,
|
||||
map: result.map,
|
||||
};
|
||||
},
|
||||
});
|
1
npm
1
npm
|
@ -7,6 +7,7 @@ docker run \
|
|||
--rm \
|
||||
--volume $(pwd):/workspace \
|
||||
--workdir /workspace \
|
||||
--env NODE_OPTIONS="--experimental-vm-modules --no-warnings" \
|
||||
--entrypoint npm \
|
||||
node:16.13.1-alpine3.14 \
|
||||
$@
|
||||
|
|
1
npx
1
npx
|
@ -7,6 +7,7 @@ docker run \
|
|||
--rm \
|
||||
--volume $(pwd):/workspace \
|
||||
--workdir /workspace \
|
||||
--env NODE_OPTIONS="--experimental-vm-modules --no-warnings" \
|
||||
--entrypoint npx \
|
||||
node:16.13.1-alpine3.14 \
|
||||
$@
|
||||
|
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
14
package.json
14
package.json
|
@ -1,16 +1,28 @@
|
|||
{
|
||||
"devDependencies": {
|
||||
"@typescript-eslint/eslint-plugin": "^5.9.0",
|
||||
"@types/jest": "27.4.0",
|
||||
"@typescript-eslint/eslint-plugin": "5.9.0",
|
||||
"@typescript-eslint/parser": "5.9.0",
|
||||
"esbuild": "0.14.11",
|
||||
"eslint": "8.6.0",
|
||||
"eslint-config-google": "0.14.0",
|
||||
"eslint-config-prettier": "8.3.0",
|
||||
"eslint-plugin-prettier": "4.0.0",
|
||||
"jest": "27.4.7",
|
||||
"prettier": "2.5.1",
|
||||
"stylelint-config-prettier": "9.0.3",
|
||||
"stylelint-config-standard": "24.0.0",
|
||||
"stylelint-order": "5.0.0",
|
||||
"stylelint-prettier": "2.0.0",
|
||||
"typescript": "4.5.4"
|
||||
},
|
||||
"jest": {
|
||||
"extensionsToTreatAsEsm": [
|
||||
".ts"
|
||||
],
|
||||
"testEnvironment": "jsdom",
|
||||
"transform": {
|
||||
"\\.ts$": "<rootDir>/jest-transform.cjs"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
"compilerOptions": {
|
||||
/* Visit https://aka.ms/tsconfig.json to read more about this file */
|
||||
"target": "es2018",
|
||||
"module": "es2020",
|
||||
"isolatedModules": true,
|
||||
"esModuleInterop": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
|
|
Загрузка…
Ссылка в новой задаче