Skip to content

Commit 18ed667

Browse files
Refactor and fixes
1 parent 7aebcad commit 18ed667

File tree

1 file changed

+16
-17
lines changed

1 file changed

+16
-17
lines changed

src/commands/test.js

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -78,14 +78,14 @@ module.exports = {
7878
}
7979

8080
if(docker_opt) {
81-
runDocker(coverage_opt, datasource, version_opt)
81+
runDocker(coverage_opt, datasource, version_opt, print)
8282
} else {
83-
runBinary(coverage_opt, datasource, force_opt, logs_opt, version_opt)
83+
runBinary(coverage_opt, datasource, force_opt, logs_opt, version_opt, print)
8484
}
8585
}
8686
}
8787

88-
async function runBinary(coverage_opt, datasource, force_opt, logs_opt, version_opt) {
88+
async function runBinary(coverage_opt, datasource, force_opt, logs_opt, version_opt, print) {
8989
const platform = getPlatform(logs_opt)
9090

9191
if (!version_opt) {
@@ -104,8 +104,8 @@ async function runBinary(coverage_opt, datasource, force_opt, logs_opt, version_
104104
force_opt ? await binary.install(true) : await binary.install(false)
105105
let args = ""
106106

107-
if (datasource) { args = datasource }
108-
if (coverage_opt) { args = args + ' -c' }
107+
datasource ? args = datasource : args
108+
coverage_opt ? args = args + ' -c' : args
109109
args !== '' ? binary.run(args.trim()) : binary.run()
110110
}
111111

@@ -144,9 +144,9 @@ function getPlatform(logs_opt) {
144144
throw new Error(`Unsupported platform: ${type} ${arch} ${majorVersion}`)
145145
}
146146

147-
function runDocker(coverage_opt, datasource, version_opt) {
148-
// Remove the binaries before because there are permission issues
149-
// with the binaries when building the docker images
147+
function runDocker(coverage_opt, datasource, version_opt, print) {
148+
// Remove binary-install-raw binaries, because docker has permission issues
149+
// when building the docker images
150150
fs.rmSync("node_modules/binary-install-raw/bin", { force: true, recursive: true });
151151

152152
let dir = 'tests/.docker';
@@ -155,15 +155,14 @@ function runDocker(coverage_opt, datasource, version_opt) {
155155
fs.mkdirSync(dir, { recursive: true });
156156
}
157157

158-
fs.writeFileSync('tests/.docker/Dockerfile', dockerfile(version_opt), (err) => {
159-
if (err) {
160-
print.info('A problem occurred while generating the Dockerfile. Please attend to the errors below.');
161-
print.info(err);
162-
}
163-
else {
164-
print.info('Successfully generated Dockerfile.')
165-
}
166-
})
158+
try {
159+
fs.writeFileSync(`${dir}/Dockerfile`, dockerfile(version_opt))
160+
print.info('Successfully generated Dockerfile.');
161+
} catch (error) {
162+
print.info('A problem occurred while generating the Dockerfile. Please attend to the errors below:');
163+
print.info(chalk.red(error));
164+
return
165+
}
167166

168167
// Run a command to check if matchstick image already exists
169168
exec('docker images -q matchstick', (error, stdout, stderr) => {

0 commit comments

Comments
 (0)