Only build gotify once in tests with make test-js
This commit is contained in:
parent
f7b593e7b1
commit
0f9d3bde81
4
Makefile
4
Makefile
|
|
@ -24,7 +24,9 @@ test-coverage:
|
||||||
done
|
done
|
||||||
|
|
||||||
test-js:
|
test-js:
|
||||||
(cd ui && CI=true npm test)
|
go build -o removeme/gotify app.go
|
||||||
|
(cd ui && CI=true GOTIFY_EXE=../removeme/gotify npm test)
|
||||||
|
rm -rf removeme
|
||||||
|
|
||||||
check-go:
|
check-go:
|
||||||
go vet ./...
|
go vet ./...
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ import {spawn, exec, ChildProcess} from 'child_process';
|
||||||
import rimraf from 'rimraf';
|
import rimraf from 'rimraf';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import puppeteer, {Browser, Page} from 'puppeteer';
|
import puppeteer, {Browser, Page} from 'puppeteer';
|
||||||
|
import fs from 'fs';
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
import wait from 'wait-on';
|
import wait from 'wait-on';
|
||||||
import kill from 'tree-kill';
|
import kill from 'tree-kill';
|
||||||
|
|
@ -16,9 +17,11 @@ export interface GotifyTest {
|
||||||
|
|
||||||
const windowsPrefix = process.platform === 'win32' ? '.exe' : '';
|
const windowsPrefix = process.platform === 'win32' ? '.exe' : '';
|
||||||
const appDotGo = path.join(__dirname, '..', '..', '..', 'app.go');
|
const appDotGo = path.join(__dirname, '..', '..', '..', 'app.go');
|
||||||
|
const testBuildPath = path.join(__dirname, 'build');
|
||||||
|
|
||||||
export const newTest = async (): Promise<GotifyTest> => {
|
export const newTest = async (): Promise<GotifyTest> => {
|
||||||
const port = await getPort();
|
const port = await getPort();
|
||||||
|
|
||||||
const gotifyFile = testFilePath();
|
const gotifyFile = testFilePath();
|
||||||
|
|
||||||
await buildGoExecutable(gotifyFile);
|
await buildGoExecutable(gotifyFile);
|
||||||
|
|
@ -54,7 +57,7 @@ const testFilePath = (): string => {
|
||||||
.toString(36)
|
.toString(36)
|
||||||
.substring(2, 15);
|
.substring(2, 15);
|
||||||
const filename = 'gotifytest_' + random + windowsPrefix;
|
const filename = 'gotifytest_' + random + windowsPrefix;
|
||||||
return path.join(__dirname, 'build', filename);
|
return path.join(testBuildPath, filename);
|
||||||
};
|
};
|
||||||
|
|
||||||
const waitForGotify = (url: string): Promise<void> => {
|
const waitForGotify = (url: string): Promise<void> => {
|
||||||
|
|
@ -71,7 +74,20 @@ const waitForGotify = (url: string): Promise<void> => {
|
||||||
};
|
};
|
||||||
|
|
||||||
const buildGoExecutable = (filename: string): Promise<void> => {
|
const buildGoExecutable = (filename: string): Promise<void> => {
|
||||||
return new Promise((resolve) => exec(`go build -o ${filename} ${appDotGo}`, () => resolve()));
|
const envGotify = process.env.GOTIFY_EXE;
|
||||||
|
if (envGotify) {
|
||||||
|
if (!fs.existsSync(testBuildPath)) {
|
||||||
|
fs.mkdirSync(testBuildPath);
|
||||||
|
}
|
||||||
|
fs.copyFileSync(envGotify, filename);
|
||||||
|
process.stdout.write(`### Copying ${envGotify} to ${filename}\n`);
|
||||||
|
return Promise.resolve();
|
||||||
|
} else {
|
||||||
|
process.stdout.write(`### Building Gotify ${filename}\n`);
|
||||||
|
return new Promise((resolve) =>
|
||||||
|
exec(`go build -o ${filename} ${appDotGo}`, () => resolve())
|
||||||
|
);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const startGotify = (filename: string, port: number): ChildProcess => {
|
const startGotify = (filename: string, port: number): ChildProcess => {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue