From 329bfd090d9d70dc3e150f21451c8069c009d882 Mon Sep 17 00:00:00 2001 From: kookookchoozeus Date: Sun, 24 Apr 2016 12:03:57 +0100 Subject: [PATCH] Fixes CLI tests for windows (#560) * Fixes CLI tests for windows * Hijacked exec so we don't have to wrap each command in changeForOS, and made replacing 'cat' safer with word boundaries * Fixing changed tests to be more consistent with the code base --- test/cli-test.js | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/test/cli-test.js b/test/cli-test.js index efd11f3..1e78eea 100644 --- a/test/cli-test.js +++ b/test/cli-test.js @@ -2,12 +2,28 @@ require('./helper'); var fs = require('fs'); var path = require('path'); +var child_process = require('child_process'); var _files = path.join(__dirname, '_files'); var cliTxt = path.resolve(_files, 'cli.txt'); var cliPartialsTxt = path.resolve(_files, 'cli_with_partials.txt'); var moduleVersion = require('../package').version; -var exec = require('child_process').exec; +function changeForOS(command) { + + if(process.platform === 'win32') { + return command + .replace(/bin\/mustache/g, 'node bin\\mustache') + .replace(/\bcat\b/g, 'type') + .replace(/\//g, '\\'); + } + + return command; +} + +function exec() { + arguments[0] = changeForOS(arguments[0]); + return child_process.exec.apply(child_process, arguments); +} describe('Mustache CLI', function () { @@ -83,14 +99,14 @@ describe('Mustache CLI', function () { it('writes it couldnt find template into stderr when second argument doesnt resolve to a file', function(done) { exec('bin/mustache test/_files/cli.json test/_files/non-existing-template.mustache', function(err, stdout, stderr) { - assert.notEqual(stderr.indexOf('Could not find file: test/_files/non-existing-template.mustache'), -1); + assert.isOk(/Could not find file: .+non-existing-template\.mustache/.test(stderr)); done(); }); }); it('writes it couldnt find view into stderr when first argument doesnt resolve to a file', function(done) { exec('bin/mustache test/_files/non-existing-view.json test/_files/cli.mustache', function(err, stdout, stderr) { - assert.notEqual(stderr.indexOf('Could not find file: test/_files/non-existing-view.json'), -1); + assert.isOk(/Could not find file: .+non-existing-view\.json/.test(stderr)); done(); }); });