Skip to content

Commit 09ea11d

Browse files
benjaminapetersenrhamilto
authored andcommitted
Add addExtension helper
Add resetExtensions() fn to helpers/extensions.js
1 parent b629f78 commit 09ea11d

File tree

2 files changed

+71
-0
lines changed

2 files changed

+71
-0
lines changed

test/integration/features/user_creates_from_url.spec.js

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ require('jasmine-beforeall');
44

55
const h = require('../helpers');
66
const addExtension = require('../helpers/extensions').addExtension;
7+
const resetExtensions = require('../helpers/extensions').resetExtensions;
78
const matchersHelpers = require('../helpers/matchers');
89
const projectHelpers = require('../helpers/project');
910
const inputsHelpers = require('../helpers/inputs');
@@ -48,6 +49,7 @@ describe('authenticated e2e-user', function() {
4849

4950
afterAll(function() {
5051
projectHelpers.deleteAllProjects();
52+
resetExtensions();
5153
h.afterAllTeardown();
5254
});
5355

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
'use strict';
2+
3+
const fs = require('fs');
4+
const path = require('path');
5+
6+
// unfortunately we have to modify the file stored in .tmp/extensions.js
7+
// since our tests run after grunt does its its copy/build step.
8+
let filePath = path.join(__dirname, '../../../.tmp', 'scripts');
9+
let fileName = path.join(filePath, 'extensions.js');
10+
// a cache of the first read so we can reset easily
11+
let cacheFileContents;
12+
13+
let read = (fileName, cb) => {
14+
return fs.readFile(fileName, 'utf-8', cb);
15+
};
16+
17+
let write = (fileName, contents, cb) => {
18+
return fs.writeFile(fileName, contents, 'utf-8', cb);
19+
};
20+
21+
// creates a cache of the .tmp/extensions.js file.
22+
// NOTE: addExtension() will also cache the first file read if it has never yet been cached.
23+
exports.cacheCurrentExtensions = () => {
24+
read(fileName, (readErr, fileContents) => {
25+
cacheFileContents = fileContents;
26+
if(readErr) {
27+
console.log('cacheCurrentExtensions() read error:', readErr);
28+
return;
29+
}
30+
});
31+
};
32+
33+
// to use: a template literal is probably the easiest way to provide JS to inject into the
34+
// extensions.js file. Please wrap in IIFE as addExtension() may be called multiple times &
35+
// the file contents will be concatenated:
36+
// var jsToWrite = `
37+
// (function() {
38+
// // createFromURL test file ${testTime} // (can use interpolation))
39+
// window.OPENSHIFT_CONSTANTS.CREATE_FROM_URL_WHITELIST = ['openshift', 'template-dumpster'];
40+
// })();
41+
// `;
42+
// adding to the extension.js file:
43+
// addExtension(jsToWrite)
44+
exports.addExtension = (fileContents) => {
45+
read(fileName, (readErr, originalFile) => {
46+
if(!cacheFileContents) {
47+
cacheFileContents = originalFile;
48+
}
49+
if(readErr) {
50+
console.log('addExtension() read error:', readErr);
51+
return;
52+
}
53+
write(fileName, originalFile + fileContents, (writeErr) => {
54+
if(writeErr) {
55+
console.log('addExtension() write error:', writeErr);
56+
return;
57+
}
58+
});
59+
});
60+
};
61+
62+
// sets the .tmp/extensions.js file either back to the original contents, or wipes it clean.
63+
exports.resetExtensions = () => {
64+
write(fileName, cacheFileContents || '', (writeErr) => {
65+
if(writeErr) {
66+
console.log('resetExtensions() write error:', writeErr);
67+
}
68+
});
69+
};

0 commit comments

Comments
 (0)