Skip to content

Commit 62eb271

Browse files
Remove hardcoded ./tests folder. Do not chache the build command.
1 parent 1ec33c6 commit 62eb271

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

src/commands/test.js

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@ const fs = require('fs')
66
const { fixParameters } = require('../command-helpers/gluegun')
77
const semver = require('semver')
88
const { spawn, exec } = require('child_process')
9+
const yaml = require('js-yaml')
910

1011
const HELP = `
1112
${chalk.bold('graph test')} ${chalk.dim('[options]')} ${chalk.bold('<datasource>')}
1213
1314
${chalk.dim('Options:')}
14-
-c, --coverage Run the tests in coverage mode. Works with v0.2.1 and above (0.2.2 and above in docker mode)
15+
-c, --coverage Run the tests in coverage mode. Works with v0.2.1 and above
1516
-d, --docker Run the tests in a docker container(Note: Please execute from the root folder of the subgraph)
1617
-f --force Binary - overwrites folder + file when downloading. Docker - rebuilds the docker image
1718
-h, --help Show usage information
@@ -145,16 +146,25 @@ function getPlatform(logsOpt) {
145146
function runDocker(coverageOpt, datasource, versionOpt, latestVersion, forceOpt, print) {
146147
// Remove binary-install-raw binaries, because docker has permission issues
147148
// when building the docker images
148-
fs.rmSync("node_modules/binary-install-raw/bin", { force: true, recursive: true });
149+
fs.rmSync("./node_modules/binary-install-raw/bin", { force: true, recursive: true });
149150

150-
let dir = 'tests/.docker';
151+
let dockerDir = "";
151152

152-
if (!fs.existsSync(dir)){
153-
fs.mkdirSync(dir, { recursive: true });
153+
try {
154+
let doc = yaml.load(fs.readFileSync('subgraph.yaml', 'utf8'))
155+
testsFolder = doc.testsFolder || './tests'
156+
dockerDir = testsFolder.endsWith('/') ? testsFolder + '.docker' : testsFolder + '/.docker'
157+
} catch (e) {
158+
print.error(e);
159+
return
160+
}
161+
162+
if (!fs.existsSync(dockerDir)){
163+
fs.mkdirSync(dockerDir, { recursive: true });
154164
}
155165

156166
try {
157-
fs.writeFileSync(`${dir}/Dockerfile`, dockerfile(versionOpt, latestVersion))
167+
fs.writeFileSync(`${dockerDir}/Dockerfile`, dockerfile(versionOpt, latestVersion))
158168
print.info('Successfully generated Dockerfile.');
159169
} catch (error) {
160170
print.info('A problem occurred while generating the Dockerfile. Please attend to the errors below:');
@@ -200,14 +210,15 @@ function runDocker(coverageOpt, datasource, versionOpt, latestVersion, forceOpt,
200210
// run a container from that image.
201211
spawn(
202212
'docker',
203-
['build', '-f', 'tests/.docker/Dockerfile', '-t', 'matchstick', '.'],
213+
['build', '--no-cache', '-f', `${dockerDir}/Dockerfile`, '-t', 'matchstick', '.'],
204214
{ stdio: 'inherit' }
205215
).on('close', code => {
206216
if (code === 0) {
207217
spawn('docker', dockerRunOpts, { stdio: 'inherit' });
208218
}
209219
})
210220
} else {
221+
print.info("Docker image already exists. Skipping `docker build` command.")
211222
// Run the container from the existing matchstick docker image
212223
spawn('docker', dockerRunOpts, { stdio: 'inherit' });
213224
}
@@ -227,6 +238,7 @@ function dockerfile(versionOpt, latestVersion) {
227238
RUN apt install -y git
228239
RUN apt install -y postgresql
229240
RUN apt install -y curl
241+
RUN apt install -y cmake
230242
RUN npm install -g @graphprotocol/graph-cli
231243
232244
# Download the latest linux binary

0 commit comments

Comments
 (0)