Skip to content

Commit

Permalink
website: add support for JS/TS unit testing
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
jamalc committed Jan 11, 2022
1 parent 60e69ee commit 6f4aa0e
Show file tree
Hide file tree
Showing 8 changed files with 7,007 additions and 1,076 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
root: true
extends: google
parserOptions:
ecmaVersion: 6
ecmaVersion: 2018
rules:
require-jsdoc: 'off'
indent: 'off'
Expand Down
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
26 changes: 26 additions & 0 deletions jest-transform.cjs
Original file line number Diff line number Diff line change
@@ -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 change: 1 addition & 0 deletions npm
Original file line number Diff line number Diff line change
Expand Up @@ -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 change: 1 addition & 0 deletions npx
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
$@
Loading

0 comments on commit 6f4aa0e

Please sign in to comment.