Skip to content

Commit

Permalink
Create test-specific temp directories to get the tests passing.
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonramirez committed May 3, 2024
1 parent bb94486 commit 0525151
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions test/unit-tests.js
Original file line number Diff line number Diff line change
@@ -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');
Expand Down Expand Up @@ -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('{');
Expand All @@ -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() {
Expand Down

0 comments on commit 0525151

Please sign in to comment.