Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add frontend testing, require node 12 #15315

Merged
merged 5 commits into from
Apr 8, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
silverwind marked this conversation as resolved.
Show resolved Hide resolved

outputs:
home:
Expand Down
10 changes: 10 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export default {
setupFilesAfterEnv: ['jest-extended'],
testTimeout: 20000,
testMatch: [
'**/web_src/**/*.test.js',
],
transform: {},
verbose: false,
};

Loading