diff --git a/test/unit-tests.js b/test/unit-tests.js index 2d7f2ea..755413b 100644 --- a/test/unit-tests.js +++ b/test/unit-tests.js @@ -1,3 +1,5 @@ +const fs = require('fs'); +const path = require('path'); const grunt = require('grunt'); const jsonlint = require('@prantlf/jsonlint'); const validator = require('@prantlf/jsonlint/lib/validator'); @@ -264,12 +266,16 @@ function testReformattingFile(indent) { } } + // Grunt <= 1.5 always tries to create the directory on Linux, even when it exists. + // Let's give it a new directory. + const temp = path.dirname(fs.mkdtempSync(`${__dirname}${path.sep}`)); + // Build an unformatted file for testing. - grunt.file.write(`${__dirname}/reformat-this.json`, '{"somethingsomething":"something","something":"dark side"}'); + grunt.file.write(`${__dirname}/${temp}/reformat-this.json`, '{"somethingsomething":"something","something":"dark side"}'); - runWithFiles(grunt, jsonlint, [ 'test/reformat-this.json' ], options); + runWithFiles(grunt, jsonlint, [ `test/${temp}/reformat-this.json` ], options); - const formatted = grunt.file.read(`${__dirname}/reformat-this.json`); + const formatted = grunt.file.read(`${__dirname}/${temp}/reformat-this.json`); const lines = formatted.split(/\r?\n/); expect(lines).to.have.length(5); expect(lines[0]).to.be('{'); @@ -278,7 +284,7 @@ function testReformattingFile(indent) { expect(lines[3]).to.be('}'); expect(lines[4]).to.be.empty(); - grunt.file.delete(`${__dirname}/reformat-this.json`); + grunt.file.delete(`${__dirname}/${temp}/reformat-this.json`); } function testSortingObjectKeys() {