Skip to content

Commit

Permalink
fix: fix tests on Window
Browse files Browse the repository at this point in the history
  • Loading branch information
juanjoDiaz committed Feb 21, 2022
1 parent 5d319ec commit cdddbbe
Showing 1 changed file with 28 additions and 27 deletions.
55 changes: 28 additions & 27 deletions test/removeNPMAbsolutePaths.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
'use strict';

const fs = require('fs');
const path = require('path');
const chai = require('chai');
const sinon = require('sinon');
const sinonChai = require('sinon-chai');
Expand Down Expand Up @@ -64,7 +65,7 @@ describe('removeNPMAbsolutePaths.js', function () {
});

it('fails if file path is invalid', function () {
const filePath = `${__dirname}/FAKE_PATH/module/package.json`;
const filePath = path.join(__dirname, 'FAKE_PATH', 'module', 'package.json');
const promise = removeNPMAbsolutePaths(filePath);
return expect(promise).to.be.rejectedWith('Can\'t read directory/file')
.then(() => {
Expand All @@ -76,7 +77,7 @@ describe('removeNPMAbsolutePaths.js', function () {
});

it('fails if file path is not package.json', function () {
const filePath = `${__dirname}/data/not_package_json/module/not_package.json`;
const filePath = path.join(__dirname, 'data', 'not_package_json', 'module', 'not_package.json');
const promise = removeNPMAbsolutePaths(filePath);
return expect(promise).to.be.rejectedWith('Invalid path provided')
.then(() => {
Expand All @@ -88,7 +89,7 @@ describe('removeNPMAbsolutePaths.js', function () {
});

it('fails if directory path is invalid', function () {
const dirPath = `${__dirname}/FAKE_PATH`;
const dirPath = path.join(__dirname, 'FAKE_PATH');
const promise = removeNPMAbsolutePaths(dirPath);
return expect(promise).to.be.rejectedWith('Can\'t read directory/file')
.then(() => {
Expand All @@ -100,8 +101,8 @@ describe('removeNPMAbsolutePaths.js', function () {
});

it('do nothing directory path doesn\'t contain package.json', function () {
const dirPath = `${__dirname}/data/not_package_json`;
const filePath = `${dirPath}/module/package.json`;
const dirPath = path.join(__dirname, 'data', 'not_package_json');
const filePath = path.join(dirPath, 'module', 'package.json');
const promise = removeNPMAbsolutePaths(dirPath);
return expect(promise).be.fulfilled
.then((results) => {
Expand All @@ -117,8 +118,8 @@ describe('removeNPMAbsolutePaths.js', function () {

describe('directory path', function () {
it('return error on malformed files if file is malformed', function () {
const dirPath = `${__dirname}/data/malformed`;
const filePath = `${dirPath}/module/package.json`;
const dirPath = path.join(__dirname, 'data', 'malformed');
const filePath = path.join(dirPath, 'module', 'package.json');
const promise = removeNPMAbsolutePaths(dirPath);
return expect(promise).be.fulfilled
.then((results) => {
Expand All @@ -137,8 +138,8 @@ describe('removeNPMAbsolutePaths.js', function () {
});

it('rewrite pacakge.json if contains _fields', function () {
const dirPath = `${__dirname}/data/underscore_fields`;
const filePath = `${dirPath}/module/package.json`;
const dirPath = path.join(__dirname, 'data', 'underscore_fields');
const filePath = path.join(dirPath, 'module', 'package.json');
const promise = removeNPMAbsolutePaths(dirPath);
return expect(promise).be.fulfilled
.then((results) => {
Expand All @@ -157,8 +158,8 @@ describe('removeNPMAbsolutePaths.js', function () {

describe('force', function () {
it('doesn\'t rewrite pacakge.json if doesn\'t contain _fields and force option isn\'t passed', function () {
const dirPath = `${__dirname}/data/no_underscore_fields`;
const filePath = `${dirPath}/module/package.json`;
const dirPath = path.join(__dirname, 'data', 'no_underscore_fields');
const filePath = path.join(dirPath, 'module', 'package.json');
const promise = removeNPMAbsolutePaths(dirPath);
return expect(promise).be.fulfilled
.then((results) => {
Expand All @@ -174,8 +175,8 @@ describe('removeNPMAbsolutePaths.js', function () {
});

it('rewrite pacakge.json if doesn\'t contain _fields and force option is passed', function () {
const dirPath = `${__dirname}/data/no_underscore_fields`;
const filePath = `${dirPath}/module/package.json`;
const dirPath = path.join(__dirname, 'data', 'no_underscore_fields');
const filePath = path.join(dirPath, 'module', 'package.json');
const promise = removeNPMAbsolutePaths(dirPath, { force: true });
return expect(promise).be.fulfilled
.then((results) => {
Expand All @@ -193,7 +194,7 @@ describe('removeNPMAbsolutePaths.js', function () {

describe('fields', function () {
it('return error if fields option is passed but is not an array', function () {
const dirPath = `${__dirname}/data/underscore_fields`;
const dirPath = path.join(__dirname, 'data', 'underscore_fields');
const opts = {
fields: 'string_value',
};
Expand All @@ -208,7 +209,7 @@ describe('removeNPMAbsolutePaths.js', function () {
});

it('return error if fields option is passed but is empty', function () {
const dirPath = `${__dirname}/data/underscore_fields`;
const dirPath = path.join(__dirname, 'data' ,'underscore_fields');
const opts = {
fields: [],
};
Expand All @@ -223,8 +224,8 @@ describe('removeNPMAbsolutePaths.js', function () {
});

it('rewrite only user-specified fields in package.json if fields option is passed', function () {
const dirPath = `${__dirname}/data/underscore_fields`;
const filePath = `${dirPath}/module/package.json`;
const dirPath = path.join(__dirname, 'data', 'underscore_fields');
const filePath = path.join(dirPath, 'module', 'package.json');
const opts = {
fields: ['_inBundle', '_where'],
};
Expand All @@ -251,7 +252,7 @@ describe('removeNPMAbsolutePaths.js', function () {

describe('file path', function () {
it('return error on malformed files if file is malformed', function () {
const filePath = `${__dirname}/data/malformed/module/package.json`;
const filePath = path.join(__dirname, 'data', 'malformed', 'module', 'package.json');
const promise = removeNPMAbsolutePaths(filePath);
return expect(promise).be.fulfilled
.then((results) => {
Expand All @@ -270,7 +271,7 @@ describe('removeNPMAbsolutePaths.js', function () {
});

it('rewrite file if contains _fields', function () {
const filePath = `${__dirname}/data/underscore_fields/module/package.json`;
const filePath = path.join(__dirname, 'data', 'underscore_fields', 'module', 'package.json');
const promise = removeNPMAbsolutePaths(filePath);
return expect(promise).be.fulfilled
.then((results) => {
Expand All @@ -289,7 +290,7 @@ describe('removeNPMAbsolutePaths.js', function () {

describe('force', function () {
it('doesn\'t rewrite file if doesn\'t contain _fields and force option isn\'t passed', function () {
const filePath = `${__dirname}/data/no_underscore_fields/module/package.json`;
const filePath = path.join(__dirname, 'data', 'no_underscore_fields', 'module', 'package.json');
const promise = removeNPMAbsolutePaths(filePath);
return expect(promise).be.fulfilled
.then((results) => {
Expand All @@ -305,7 +306,7 @@ describe('removeNPMAbsolutePaths.js', function () {
});

it('rewrite file if doesn\'t contain _fields and force option is passed', function () {
const filePath = `${__dirname}/data/no_underscore_fields/module/package.json`;
const filePath = path.join(__dirname, 'data', 'no_underscore_fields', 'module', 'package.json');
const promise = removeNPMAbsolutePaths(filePath, { force: true });
return expect(promise).be.fulfilled
.then((results) => {
Expand All @@ -323,7 +324,7 @@ describe('removeNPMAbsolutePaths.js', function () {

describe('fields', function () {
it('return error if fields option is passed but is not an array', function () {
const filePath = `${__dirname}/data/underscore_fields/module/package.json`;
const filePath = path.join(__dirname, 'data' , 'underscore_fields' , 'module' , 'package.json');
const opts = {
fields: 'string_value',
};
Expand All @@ -338,7 +339,7 @@ describe('removeNPMAbsolutePaths.js', function () {
});

it('return error if fields option is passed but is empty', function () {
const filePath = `${__dirname}/data/underscore_fields/module/package.json`;
const filePath = path.join(__dirname, 'data', 'underscore_fields', 'module', 'package.json');
const opts = {
fields: [],
};
Expand All @@ -353,7 +354,7 @@ describe('removeNPMAbsolutePaths.js', function () {
});

it('rewrite only user-specified fields in package.json if fields option is passed', function () {
const filePath = `${__dirname}/data/underscore_fields/module/package.json`;
const filePath = path.join(__dirname, 'data', 'underscore_fields', 'module', 'package.json');
const opts = {
fields: ['_inBundle', '_where'],
};
Expand Down Expand Up @@ -412,7 +413,7 @@ describe('removeNPMAbsolutePaths.js', function () {
const err = new Error('Can\'t read directory.');
readdir.yields(err);
clearCachedModuleSoNewMocksWork();
const dirPath = `${__dirname}/data/underscore_fields`;
const dirPath = path.join(__dirname, 'data', 'underscore_fields');
const promise = removeNPMAbsolutePaths(dirPath);
return expect(promise).be.fulfilled
.then((results) => {
Expand Down Expand Up @@ -462,7 +463,7 @@ describe('removeNPMAbsolutePaths.js', function () {
const err = new Error('Can\'t read file.');
readFile.yields(err);
clearCachedModuleSoNewMocksWork();
const filePath = `${__dirname}/data/underscore_fields/module/package.json`;
const filePath = path.join(__dirname, 'data', 'underscore_fields', 'module', 'package.json');
const promise = removeNPMAbsolutePaths(filePath);
return expect(promise).be.fulfilled
.then((results) => {
Expand Down Expand Up @@ -512,7 +513,7 @@ describe('removeNPMAbsolutePaths.js', function () {
const err = new Error('Can\'t write to file.');
writeFile.yields(err);
clearCachedModuleSoNewMocksWork();
const filePath = `${__dirname}/data/underscore_fields/module/package.json`;
const filePath = path.join(__dirname, 'data', 'underscore_fields', 'module', 'package.json');
const promise = removeNPMAbsolutePaths(filePath);
return expect(promise).be.fulfilled
.then((results) => {
Expand Down

0 comments on commit cdddbbe

Please sign in to comment.