Skip to content

Commit

Permalink
Build: Ensure tests pass on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
phated committed Feb 25, 2019
1 parent 404eb5b commit 7e69e97
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 22 deletions.
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -49,6 +49,7 @@
"mississippi": "1.X",
"mocha": "^3.5.3",
"object-assign": "^4.1.1",
"rimraf": "^2.6.3",
"vinyl": "^2.2.0"
},
"files": [
Expand Down
5 changes: 4 additions & 1 deletion test/.eslintrc
@@ -1,3 +1,6 @@
{
"extends": "gulp/test"
"extends": "gulp/test",
"rules": {
"no-console": 0
}
}
5 changes: 5 additions & 0 deletions test/integration.test.js
Expand Up @@ -6,6 +6,7 @@ var $ = require('gulp-load-plugins')();
var sourcemaps = require('..');
var debug = require('debug-fabulous')();
var miss = require('mississippi');
var rimraf = require('rimraf');

var pipe = miss.pipe;
var concat = miss.concat;
Expand All @@ -28,6 +29,10 @@ debug('running');

describe('integrations', function() {

after(function(cb) {
rimraf('./tmp', cb);
});

it('combined: creates inline mapping', function(done) {

function assert(results) {
Expand Down
16 changes: 14 additions & 2 deletions test/publish.test.js
@@ -1,23 +1,35 @@
'use strict';

var os = require('os');
var exec = require('child_process').exec;
var rimraf = require('rimraf');

var isWindows = (os.platform() === 'win32');

function cleanUp(cb) {
return exec('rm -rf ./tmp', cb);
rimraf('./tmp', cb);
}

function makeTestPackage(cb) {
if (isWindows) {
this.skip();
}

return exec('./scripts/mockPublish', cb);
}


describe('mock publish', function() {

beforeEach(makeTestPackage);
afterEach(cleanUp);
after(cleanUp);

// with regards to averting npm publishing disasters https://github.com/gulp-sourcemaps/gulp-sourcemaps/issues/246
it('can load a published version', function(done) {
if (isWindows) {
this.skip();
}

try {
// attempt to load a packed / unpacked potential deployed version
require('../tmp/package/index');
Expand Down
40 changes: 21 additions & 19 deletions test/write.test.js
Expand Up @@ -233,15 +233,16 @@ describe('write', function() {

function assert(results) {
var dataFile = results[1];
expect(/assets\/helloworld.js/.test(dataFile.path)).toEqual(true);
console.log('debugging', dataFile.path);
expect(dataFile.path).toEqual(path.join(__dirname, 'assets/helloworld.js'));
expect(dataFile instanceof File).toEqual(true);
expect(dataFile).toBe(file);
expect(dataFile.contents.toString()).toEqual(sourceContent + '\n//# sourceMappingURL=../maps/helloworld.js.map\n');
expect(dataFile.sourceMap.file).toEqual('../dist/helloworld.js');

var mapFile = results[0];
expect(mapFile instanceof File).toEqual(true);
expect(/maps\/helloworld.js.map/.test(mapFile.path)).toEqual(true);
expect(mapFile.path).toEqual(path.join(__dirname, 'maps/helloworld.js.map'));
expect(JSON.parse(mapFile.contents)).toEqual(dataFile.sourceMap);
expect(mapFile.stat.isFile()).toEqual(true);
expect(mapFile.stat.isDirectory()).toEqual(false);
Expand All @@ -264,8 +265,8 @@ describe('write', function() {

function assert(results) {
var data = results[0];
expect(/maps\/helloworld.js.map/.test(data.path)).toEqual(true);
expect(/assets\/helloworld.js/.test(data.history[0])).toEqual(true);
expect(data.path).toEqual(path.join(__dirname, 'maps/helloworld.js.map'));
expect(data.history[0]).toEqual(path.join(__dirname, 'assets/helloworld.js'));
}

pipe([
Expand All @@ -280,15 +281,15 @@ describe('write', function() {

function assert(results) {
var dataFile = results[1];
expect(/assets\/helloworld.js/.test(dataFile.path)).toEqual(true);
expect(dataFile.path).toEqual(path.join(__dirname, 'assets/helloworld.js'));
expect(dataFile instanceof File).toEqual(true);
expect(dataFile).toBe(file);
expect(dataFile.contents.toString()).toEqual(sourceContent + '\n//# sourceMappingURL=../maps/helloworld.map\n');
expect(dataFile.sourceMap.file).toEqual('../dist/helloworld.js');

var mapFile = results[0];
expect(mapFile instanceof File).toEqual(true);
expect(/maps\/helloworld.map/.test(mapFile.path)).toEqual(true);
expect(mapFile.path).toEqual(path.join(__dirname, 'maps/helloworld.map'));
expect(JSON.parse(mapFile.contents)).toEqual(dataFile.sourceMap);
}

Expand All @@ -309,7 +310,7 @@ describe('write', function() {

function assert(results) {
var data = results[1];
expect(/assets\/dir1\/dir2\/helloworld.js/.test(data.path)).toEqual(true);
expect(data.path).toEqual(path.join(__dirname, 'assets/dir1/dir2/helloworld.js'));
expect(data.contents.toString()).toEqual(sourceContent + '\n//# sourceMappingURL=../maps/dir1/dir2/helloworld.js.map\n');
}

Expand Down Expand Up @@ -441,11 +442,11 @@ describe('write', function() {

function assert(results) {
var dataFile = results[1];
expect(/assets\/dir1\/dir2\/helloworld.js/.test(dataFile.path)).toEqual(true);
expect(dataFile.path).toEqual(path.join(__dirname, 'assets/dir1/dir2/helloworld.js'));
expect(dataFile.sourceMap.sourceRoot).toEqual('../../../assets');
expect(dataFile.sourceMap.file).toEqual('helloworld.js');
var mapFile = results[0];
expect(/assets\/dir1\/dir2\/helloworld.js.map/.test(mapFile.path)).toEqual(true);
expect(mapFile.path).toEqual(path.join(__dirname, 'assets/dir1/dir2/helloworld.js.map'));
}

pipe([
Expand All @@ -463,11 +464,11 @@ describe('write', function() {

function assert(results) {
var dataFile = results[1];
expect(/assets\/dir1\/dir2\/helloworld.js/.test(dataFile.path)).toEqual(true);
expect(dataFile.path).toEqual(path.join(__dirname, 'assets/dir1/dir2/helloworld.js'));
expect(dataFile.sourceMap.sourceRoot).toEqual('../../../src');
expect(dataFile.sourceMap.file).toEqual('helloworld.js');
var mapFile = results[0];
expect(/assets\/dir1\/dir2\/helloworld.js.map/.test(mapFile.path)).toEqual(true);
expect(mapFile.path).toEqual(path.join(__dirname, 'assets/dir1/dir2/helloworld.js.map'));
}

pipe([
Expand All @@ -482,11 +483,11 @@ describe('write', function() {

function assert(results) {
var dataFile = results[1];
expect(/assets\/dir1\/dir2\/helloworld.js/.test(dataFile.path)).toEqual(true);
expect(dataFile.path).toEqual(path.join(__dirname, 'assets/dir1/dir2/helloworld.js'));
expect(dataFile.sourceMap.sourceRoot).toEqual('../..');
expect(dataFile.sourceMap.file).toEqual('helloworld.js');
var mapFile = results[0];
expect(/assets\/dir1\/dir2\/helloworld.js.map/.test(mapFile.path)).toEqual(true);
expect(mapFile.path).toEqual(path.join(__dirname, 'assets/dir1/dir2/helloworld.js.map'));
}

pipe([
Expand All @@ -501,11 +502,11 @@ describe('write', function() {

function assert(results) {
var dataFile = results[1];
expect(/assets\/dir1\/dir2\/helloworld.js/.test(dataFile.path)).toEqual(true);
expect(dataFile.path).toEqual(path.join(__dirname, 'assets/dir1/dir2/helloworld.js'));
expect(dataFile.sourceMap.sourceRoot).toEqual('../../../../src');
expect(dataFile.sourceMap.file).toEqual('../../../dir1/dir2/helloworld.js');
var mapFile = results[0];
expect(/assets\/maps\/dir1\/dir2\/helloworld.js.map/.test(mapFile.path)).toEqual(true);
expect(mapFile.path).toEqual(path.join(__dirname, 'assets/maps/dir1/dir2/helloworld.js.map'));
}

pipe([
Expand All @@ -520,11 +521,11 @@ describe('write', function() {

function assert(results) {
var dataFile = results[1];
expect(/assets\/dir1\/dir2\/helloworld.js/.test(dataFile.path)).toEqual(true);
expect(dataFile.path).toEqual(path.join(__dirname, 'assets/dir1/dir2/helloworld.js'));
expect(dataFile.sourceMap.sourceRoot).toEqual('../../../src');
expect(dataFile.sourceMap.file).toEqual('../../../dist/dir1/dir2/helloworld.js');
var mapFile = results[0];
expect(/maps\/dir1\/dir2\/helloworld.js.map/.test(mapFile.path)).toEqual(true);
expect(mapFile.path).toEqual(path.join(__dirname, 'maps/dir1/dir2/helloworld.js.map'));
}

pipe([
Expand Down Expand Up @@ -657,14 +658,15 @@ describe('write', function() {
function assert(results) {
var data = results[1];
expect(/helloworld\.js$/.test(data.path)).toEqual(true);
expect(data.contents.toString()).toEqual(sourceContent + '\n//# sourceMappingURL=http://maps.example.com/dir1/dir2/helloworld.js.map\n');
expect(data.contents.toString()).toEqual(sourceContent + '\n//# sourceMappingURL=http://maps.example.com/helloworld.js.map\n');
}

pipe([
from.obj([file]),
sourcemaps.write('../aaa/bbb/', {
sourceMappingURL: function(file) {
return 'http://maps.example.com/' + file.relative + '.map';
// This avoids file.relative because Windows path separators
return 'http://maps.example.com/' + file.basename + '.map';
},
}),
concat(assert),
Expand Down

0 comments on commit 7e69e97

Please sign in to comment.