Skip to content

Commit df05fbd

Browse files
author
benholloway
committed
attempting to fix problem with testing on CI environment
1 parent 0bc49dd commit df05fbd

File tree

1 file changed

+34
-14
lines changed

1 file changed

+34
-14
lines changed

test/specs/tasks/build.spec.js

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,13 @@ function expectations(testCase) {
8787
// expect(workingBuildFile('index.css.map')).diffFilePatch(sourceBuildFile('index.css.map'));
8888

8989
// must remove basePath to allow karam.conf.js to be correctly diff'd
90-
var withoutBasePath = getReplacer(/^\s*basePath:.*$/gm, '');
90+
var replace = replacer()
91+
.add(/^\s*basePath:.*$/gm, '')
92+
.add(/\\{2}/g, '/')
93+
.commit();
9194

9295
// test output
93-
expect(withoutBasePath(workingTestFile('karma.conf.js'))).diffPatch(withoutBasePath(sourceTestFile('karma.conf.js')));
96+
expect(replace(workingTestFile('karma.conf.js'))).diffPatch(replace(sourceTestFile('karma.conf.js')));
9497
expect(workingTestFile('index.js')).diffFilePatch(sourceTestFile('index.js'));
9598
// TODO @bholloway solve repeatability of .map files
9699
// expect(workingTestFile('index.js.map')).diffFilePatch(sourceTestFile('index.js.map'));
@@ -112,19 +115,36 @@ function customMatchers() {
112115
});
113116
}
114117

115-
function getReplacer(before, after) {
116-
return function(pathElements) {
117-
var filePath = path.resolve.apply(path, [].concat(pathElements));
118-
var contents = fs.existsSync(filePath) && fs.readFileSync(filePath).toString();
119-
if (contents) {
120-
if (typeof before === 'string') {
121-
while (contents.indexOf(before) >= 0) {
122-
contents = contents.replace(before, after);
118+
function replacer() {
119+
var list = [];
120+
var self = {
121+
add: function(before, after) {
122+
list.push({
123+
before: before,
124+
after : after
125+
});
126+
return self;
127+
},
128+
commit: function() {
129+
return function(pathElements) {
130+
var filePath = path.resolve.apply(path, [].concat(pathElements));
131+
var text = fs.existsSync(filePath) && fs.readFileSync(filePath).toString();
132+
function replaceSingle(item) {
133+
if (text) {
134+
if (typeof item.before === 'string') {
135+
while (text.indexOf(item.before) >= 0) {
136+
text = text.replace(item.before, item.after);
137+
}
138+
} else if ((typeof item.before === 'object') && ('test' in item.before)) {
139+
text = text.replace(item.before, item.after);
140+
}
141+
}
142+
return text;
123143
}
124-
} else if ((typeof before === 'object') && ('test' in before)) {
125-
contents = contents.replace(before, after);
126-
}
144+
list.forEach(replaceSingle);
145+
return text;
146+
};
127147
}
128-
return contents;
129148
};
149+
return self;
130150
}

0 commit comments

Comments
 (0)