Skip to content

Commit 0d1a5e0

Browse files
authored
Add frontend testing, require node 12 (#15315)
- Add basic frontend unit testing infrastructure using jest in ESM mode - Rename 'make test' to 'make test-backend' - Introduce 'make test-frontend' and 'make test' that runs both - Bump Node.js requirement to v12. v10 will be EOL in less than a month. - Convert all build-related JS files to ESM. I opted to run frontend tests run as part of the compliance pipeline because they complete fast and are not platform-specific like the golang tests.
1 parent 4eea819 commit 0d1a5e0

12 files changed

+7586
-2470
lines changed

.drone.yml

+7-1
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,17 @@ steps:
7070
- make checks-backend
7171
depends_on: [lint-backend]
7272

73+
- name: test-frontend
74+
image: node:14
75+
commands:
76+
- make test-frontend
77+
depends_on: [lint-frontend]
78+
7379
- name: build-frontend
7480
image: node:14
7581
commands:
7682
- make frontend
77-
depends_on: [lint-frontend]
83+
depends_on: [test-frontend]
7884

7985
- name: build-backend-no-gcc
8086
pull: always

.eslintrc

+6
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,12 @@ overrides:
5252
rules:
5353
import/no-unresolved: [0]
5454
import/no-extraneous-dependencies: [0]
55+
- files: ["*.test.js"]
56+
env:
57+
jest: true
58+
- files: ["*.config.js"]
59+
rules:
60+
import/no-unused-modules: [0]
5561

5662
rules:
5763
accessor-pairs: [2]

Makefile

+14-4
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ COMMA := ,
2828

2929
XGO_VERSION := go-1.16.x
3030
MIN_GO_VERSION := 001014000
31-
MIN_NODE_VERSION := 010013000
31+
MIN_NODE_VERSION := 012017000
3232

3333
DOCKER_IMAGE ?= gitea/gitea
3434
DOCKER_TAG ?= latest
@@ -173,6 +173,9 @@ help:
173173
@echo " - checks run various consistency checks"
174174
@echo " - checks-frontend check frontend files"
175175
@echo " - checks-backend check backend files"
176+
@echo " - test test everything"
177+
@echo " - test-frontend test frontend files"
178+
@echo " - test-backend test backend files"
176179
@echo " - webpack build webpack files"
177180
@echo " - svg build svg files"
178181
@echo " - fomantic build fomantic files"
@@ -322,7 +325,7 @@ lint: lint-frontend lint-backend
322325

323326
.PHONY: lint-frontend
324327
lint-frontend: node_modules
325-
npx eslint --color --max-warnings=0 web_src/js build templates webpack.config.js
328+
npx eslint --color --max-warnings=0 web_src/js build templates *.config.js
326329
npx stylelint --color --max-warnings=0 web_src/less
327330

328331
.PHONY: lint-backend
@@ -345,16 +348,23 @@ watch-backend: go-check
345348
air -c .air.conf
346349

347350
.PHONY: test
348-
test:
351+
test: test-frontend test-backend
352+
353+
.PHONY: test-backend
354+
test-backend:
349355
@echo "Running go test with -tags '$(TEST_TAGS)'..."
350356
@$(GO) test $(GOTESTFLAGS) -mod=vendor -tags='$(TEST_TAGS)' $(GO_PACKAGES)
351357

358+
.PHONY: test-frontend
359+
test-frontend:
360+
@NODE_OPTIONS="--experimental-vm-modules --no-warnings" npx jest --color
361+
352362
.PHONY: test-check
353363
test-check:
354364
@echo "Running test-check...";
355365
@diff=$$(git status -s); \
356366
if [ -n "$$diff" ]; then \
357-
echo "make test has changed files in the source tree:"; \
367+
echo "make test-backend has changed files in the source tree:"; \
358368
echo "$${diff}"; \
359369
echo "You should change the tests to create these files in a temporary directory."; \
360370
echo "Do not simply add these files to .gitignore"; \

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ or if sqlite support is required:
7777
The `build` target is split into two sub-targets:
7878

7979
- `make backend` which requires [Go 1.13](https://golang.org/dl/) or greater.
80-
- `make frontend` which requires [Node.js 10.13](https://nodejs.org/en/download/) or greater.
80+
- `make frontend` which requires [Node.js 12.17](https://nodejs.org/en/download/) or greater.
8181

8282
If pre-built frontend files are present it is possible to only build the backend:
8383

build/generate-images.js

+7-8
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
#!/usr/bin/env node
2-
'use strict';
3-
4-
const imageminZopfli = require('imagemin-zopfli');
5-
const {optimize, extendDefaultPlugins} = require('svgo');
6-
const {fabric} = require('fabric');
7-
const {readFile, writeFile} = require('fs').promises;
8-
const {resolve} = require('path');
1+
import imageminZopfli from 'imagemin-zopfli';
2+
import {optimize, extendDefaultPlugins} from 'svgo';
3+
import {fabric} from 'fabric';
4+
import {readFile, writeFile} from 'fs/promises';
5+
import {resolve, dirname} from 'path';
6+
import {fileURLToPath} from 'url';
97

8+
const __dirname = dirname(fileURLToPath(import.meta.url));
109
const logoFile = resolve(__dirname, '../assets/logo.svg');
1110

1211
function exit(err) {

build/generate-svg.js

+6-7
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
#!/usr/bin/env node
2-
'use strict';
3-
4-
const fastGlob = require('fast-glob');
5-
const {optimize, extendDefaultPlugins} = require('svgo');
6-
const {resolve, parse} = require('path');
7-
const {readFile, writeFile, mkdir} = require('fs').promises;
1+
import fastGlob from 'fast-glob';
2+
import {optimize, extendDefaultPlugins} from 'svgo';
3+
import {resolve, parse, dirname} from 'path';
4+
import {readFile, writeFile, mkdir} from 'fs/promises';
5+
import {fileURLToPath} from 'url';
86

7+
const __dirname = dirname(fileURLToPath(import.meta.url));
98
const glob = (pattern) => fastGlob.sync(pattern, {cwd: resolve(__dirname), absolute: true});
109
const outputDir = resolve(__dirname, '../public/img/svg');
1110

docs/config.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ params:
2121
version: 1.13.7
2222
minGoVersion: 1.14
2323
goVersion: 1.16
24-
minNodeVersion: 10.13
24+
minNodeVersion: 12.17
2525

2626
outputs:
2727
home:

jest.config.js

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
export default {
2+
setupFilesAfterEnv: ['jest-extended'],
3+
testTimeout: 20000,
4+
testMatch: [
5+
'**/web_src/**/*.test.js',
6+
],
7+
transform: {},
8+
verbose: false,
9+
};
10+

0 commit comments

Comments
 (0)