Skip to content

Commit

Permalink
Add frontend testing, require node 12
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
silverwind committed Apr 6, 2021
1 parent 8be2cc4 commit 83726e6
Show file tree
Hide file tree
Showing 13 changed files with 7,589 additions and 2,471 deletions.
8 changes: 7 additions & 1 deletion .drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,17 @@ steps:
- make checks-backend
depends_on: [lint-backend]

- name: test-frontend
image: node:14
commands:
- make test-frontend
depends_on: [lint-frontend]

- name: build-frontend
image: node:14
commands:
- make frontend
depends_on: [lint-frontend]
depends_on: [test-frontend]

- name: build-backend-no-gcc
pull: always
Expand Down
6 changes: 6 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ overrides:
rules:
import/no-unresolved: [0]
import/no-extraneous-dependencies: [0]
- files: ["*.test.js"]
env:
jest: true
- files: ["*.config.js"]
rules:
import/no-unused-modules: [0]

rules:
accessor-pairs: [2]
Expand Down
18 changes: 14 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ COMMA := ,

XGO_VERSION := go-1.16.x
MIN_GO_VERSION := 001014000
MIN_NODE_VERSION := 010013000
MIN_NODE_VERSION := 012017000

DOCKER_IMAGE ?= gitea/gitea
DOCKER_TAG ?= latest
Expand Down Expand Up @@ -173,6 +173,9 @@ help:
@echo " - checks run various consistency checks"
@echo " - checks-frontend check frontend files"
@echo " - checks-backend check backend files"
@echo " - test test everything"
@echo " - test-frontend test frontend files"
@echo " - test-backend test backend files"
@echo " - webpack build webpack files"
@echo " - svg build svg files"
@echo " - fomantic build fomantic files"
Expand Down Expand Up @@ -322,7 +325,7 @@ lint: lint-frontend lint-backend

.PHONY: lint-frontend
lint-frontend: node_modules
npx eslint --color --max-warnings=0 web_src/js build templates webpack.config.js
npx eslint --color --max-warnings=0 web_src/js build templates *.config.js
npx stylelint --color --max-warnings=0 web_src/less

.PHONY: lint-backend
Expand All @@ -345,16 +348,23 @@ watch-backend: go-check
air -c .air.conf

.PHONY: test
test:
test: test-frontend test-backend

.PHONY: test-backend
test-backend:
@echo "Running go test with -tags '$(TEST_TAGS)'..."
@$(GO) test $(GOTESTFLAGS) -mod=vendor -tags='$(TEST_TAGS)' $(GO_PACKAGES)

.PHONY: test-frontend
test-frontend:
@NODE_OPTIONS="--experimental-vm-modules --no-warnings" npx jest --color

.PHONY: test-check
test-check:
@echo "Running test-check...";
@diff=$$(git status -s); \
if [ -n "$$diff" ]; then \
echo "make test has changed files in the source tree:"; \
echo "make test-backend has changed files in the source tree:"; \
echo "$${diff}"; \
echo "You should change the tests to create these files in a temporary directory."; \
echo "Do not simply add these files to .gitignore"; \
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ or if sqlite support is required:
The `build` target is split into two sub-targets:

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

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

Expand Down
15 changes: 7 additions & 8 deletions build/generate-images.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
#!/usr/bin/env node
'use strict';

const imageminZopfli = require('imagemin-zopfli');
const {optimize, extendDefaultPlugins} = require('svgo');
const {fabric} = require('fabric');
const {readFile, writeFile} = require('fs').promises;
const {resolve} = require('path');
import imageminZopfli from 'imagemin-zopfli';
import {optimize, extendDefaultPlugins} from 'svgo';
import {fabric} from 'fabric';
import {readFile, writeFile} from 'fs/promises';
import {resolve, dirname} from 'path';
import {fileURLToPath} from 'url';

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

function exit(err) {
Expand Down
13 changes: 6 additions & 7 deletions build/generate-svg.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
#!/usr/bin/env node
'use strict';

const fastGlob = require('fast-glob');
const {optimize, extendDefaultPlugins} = require('svgo');
const {resolve, parse} = require('path');
const {readFile, writeFile, mkdir} = require('fs').promises;
import fastGlob from 'fast-glob';
import {optimize, extendDefaultPlugins} from 'svgo';
import {resolve, parse, dirname} from 'path';
import {readFile, writeFile, mkdir} from 'fs/promises';
import {fileURLToPath} from 'url';

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

Expand Down
2 changes: 1 addition & 1 deletion docs/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ params:
version: 1.13.6
minGoVersion: 1.14
goVersion: 1.16
minNodeVersion: 10.13
minNodeVersion: 12.17.0

outputs:
home:
Expand Down
12 changes: 12 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export default {
setupFilesAfterEnv: ['jest-extended'],
testTimeout: 10000,
testPathIgnorePatterns: [
'/node_modules/',
'/public/',
'/vendor/',
],
transform: {},
verbose: false,
};

Loading

0 comments on commit 83726e6

Please sign in to comment.