Skip to content

Commit 6f4aa0e

Browse files
committed
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 <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Alex Rakoczy <[email protected]> Trust: Jamal Carvalho <[email protected]>
1 parent 60e69ee commit 6f4aa0e

File tree

8 files changed

+7007
-1076
lines changed

8 files changed

+7007
-1076
lines changed

.eslintrc.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
root: true
22
extends: google
33
parserOptions:
4-
ecmaVersion: 6
4+
ecmaVersion: 2018
55
rules:
66
require-jsdoc: 'off'
77
indent: 'off'

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,13 @@ Reference .ts files in html templates as module code.
5353

5454
`<script type="module" src="/ts/filename.ts">`
5555

56+
Write unit tests for TypeScript code using the [jest](https://jestjs.io/)
57+
testing framework.
58+
59+
### Run Jest
60+
61+
./npx jest [TestPathPattern]
62+
5663
## Deploying
5764

5865
Each time a CL is reviewed and submitted, the code is deployed to App Engine.

jest-transform.cjs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/**
2+
* @license
3+
* Copyright 2022 The Go Authors. All rights reserved.
4+
* Use of this source code is governed by a BSD-style
5+
* license that can be found in the LICENSE file.
6+
*/
7+
8+
const {transform} = require('esbuild');
9+
10+
exports.createTransformer = () => ({
11+
canInstrument: true,
12+
processAsync: async (source) => {
13+
const result = await transform(source, {
14+
loader: 'ts',
15+
});
16+
if (result.warnings.length) {
17+
result.warnings.forEach(m => {
18+
console.warn(m);
19+
});
20+
}
21+
return {
22+
code: result.code,
23+
map: result.map,
24+
};
25+
},
26+
});

npm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ docker run \
77
--rm \
88
--volume $(pwd):/workspace \
99
--workdir /workspace \
10+
--env NODE_OPTIONS="--experimental-vm-modules --no-warnings" \
1011
--entrypoint npm \
1112
node:16.13.1-alpine3.14 \
1213
$@

npx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ docker run \
77
--rm \
88
--volume $(pwd):/workspace \
99
--workdir /workspace \
10+
--env NODE_OPTIONS="--experimental-vm-modules --no-warnings" \
1011
--entrypoint npx \
1112
node:16.13.1-alpine3.14 \
1213
$@

0 commit comments

Comments
 (0)