From 0f9d3bde814a7b2110b3c900bde1b017db8a6ab9 Mon Sep 17 00:00:00 2001 From: Jannis Mattheis Date: Sat, 15 Sep 2018 10:08:38 +0200 Subject: [PATCH] Only build gotify once in tests with make test-js --- Makefile | 4 +++- ui/src/tests/setup.ts | 20 ++++++++++++++++++-- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 1ccb0f2..4dad9d0 100644 --- a/Makefile +++ b/Makefile @@ -24,7 +24,9 @@ test-coverage: done 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: go vet ./... diff --git a/ui/src/tests/setup.ts b/ui/src/tests/setup.ts index 382de11..1825052 100644 --- a/ui/src/tests/setup.ts +++ b/ui/src/tests/setup.ts @@ -3,6 +3,7 @@ import {spawn, exec, ChildProcess} from 'child_process'; import rimraf from 'rimraf'; import path from 'path'; import puppeteer, {Browser, Page} from 'puppeteer'; +import fs from 'fs'; // @ts-ignore import wait from 'wait-on'; import kill from 'tree-kill'; @@ -16,9 +17,11 @@ export interface GotifyTest { const windowsPrefix = process.platform === 'win32' ? '.exe' : ''; const appDotGo = path.join(__dirname, '..', '..', '..', 'app.go'); +const testBuildPath = path.join(__dirname, 'build'); export const newTest = async (): Promise => { const port = await getPort(); + const gotifyFile = testFilePath(); await buildGoExecutable(gotifyFile); @@ -54,7 +57,7 @@ const testFilePath = (): string => { .toString(36) .substring(2, 15); const filename = 'gotifytest_' + random + windowsPrefix; - return path.join(__dirname, 'build', filename); + return path.join(testBuildPath, filename); }; const waitForGotify = (url: string): Promise => { @@ -71,7 +74,20 @@ const waitForGotify = (url: string): Promise => { }; const buildGoExecutable = (filename: string): Promise => { - 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 => {