Skip to content

Commit c74445e

Browse files
Add comments and fix help message
1 parent 2a9bd63 commit c74445e

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

src/commands/test.js

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ const { spawn, exec } = require('child_process')
66
const fs = require('fs')
77

88
const HELP = `
9-
${chalk.bold('graph test')} ${chalk.dim('[options]')} ${chalk.bold('<datasource>')}
9+
${chalk.bold('graph test')} ${chalk.bold('<datasource>')} ${chalk.dim('[options]')}
1010
1111
${chalk.dim('Options:')}
1212
-h, --help Show usage information
1313
-v, --version <tag> Choose the version of the rust binary that you want to be downloaded/used
14+
-c, --coverage Run tests in coverage mode
1415
-f, --flags <flags>
1516
`
16-
// -r, --root The root folder of the subgraph project. Default is the folder where the 'graph test' command is executed from.
1717

1818
module.exports = {
1919
description: 'Runs rust binary for subgraph testing',
@@ -98,12 +98,14 @@ CMD ../binary-linux-20 \${ARGS}
9898
}
9999
})
100100

101-
// TODO:
102-
// 1. Check if image exists - done
103-
// 2. Check if ARGS are passed. Add them to the options there are ARGS - done
104-
// ?? 3. Add option to pass root/host folder
101+
// TODOs:
102+
// 1. Fix true/false options with gluegun.
103+
// 2. If -v/--version is passed, delete current image and build again.
105104

105+
// Run a command to check if matchstick image already exists
106106
exec('docker images -q matchstick', (error, stdout, stderr) => {
107+
// Getting the current working folder that will be passed to the
108+
// `docker run` command to be bind mounted.
107109
let current_folder = process.cwd();
108110
let args = '';
109111

@@ -119,12 +121,17 @@ CMD ../binary-linux-20 \${ARGS}
119121

120122
if(args !== '') {
121123
options.push('-e')
122-
options.push(`ARGS=${args}`);
124+
options.push(`ARGS=${args.trim()}`);
123125
}
124126

125127
options.push('matchstick')
126128

129+
// If a matchstick image does not exists, the command returns an empty string,
130+
// else it'll return the image ID. Skip `docker build` if an image already exists
131+
// Use spawn() and {stdio: 'inherit'} so we can see the logs in real time.
127132
if(stdout === "") {
133+
// Build a docker image. If the process has executed successfully
134+
// run a container from that image.
128135
spawn(
129136
'docker',
130137
['build', '-f', 'tests/.docker/Dockerfile', '-t', 'matchstick', '.'],
@@ -135,6 +142,7 @@ CMD ../binary-linux-20 \${ARGS}
135142
}
136143
})
137144
} else {
145+
// Run the container from the existing matchstick docker image
138146
spawn('docker', options, { stdio: 'inherit' });
139147
}
140148
})

0 commit comments

Comments
 (0)