Skip to content

Commit c3f9c79

Browse files
authored
Merge pull request #762 from gilest/feat/config-function
Config exports function rather than object
2 parents 922eb18 + 3d0cf7b commit c3f9c79

4 files changed

Lines changed: 49 additions & 25 deletions

File tree

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
1-
module.exports = {
2-
resilient: false,
3-
sandboxGlobals: {},
4-
setupFastboot: fastbootInstance => {
5-
// here you can access the fastboot instance which runs the tests
6-
}
1+
module.exports = () => {
2+
return {
3+
resilient: false,
4+
buildSandboxGlobals(defaultGlobals) {
5+
return {
6+
...defaultGlobals
7+
// here you can add globals to the Fastboot renderer
8+
};
9+
},
10+
setupFastboot(fastbootInstance) {
11+
// here you can access the fastboot instance which runs the tests
12+
},
13+
};
714
};

lib/helpers.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const { URL } = require('url');
77
const JSONfn = require('json-fn');
88
const FastBoot = require('fastboot');
99
const bodyParser = require('body-parser');
10+
const { deprecate } = require('util');
1011

1112
function createMockRequest(app) {
1213
app.post(
@@ -100,9 +101,20 @@ function makeFastbootTestingConfig(config, pkg) {
100101
'fastboot-testing.js'
101102
);
102103

103-
const customized = fs.existsSync(fastbootTestConfigPath)
104-
? require(fastbootTestConfigPath)
105-
: {};
104+
let customized = {};
105+
106+
if (fs.existsSync(fastbootTestConfigPath)) {
107+
const fastbootTestConfig = require(fastbootTestConfigPath);
108+
109+
if (typeof fastbootTestConfig === 'function') {
110+
customized = fastbootTestConfig();
111+
} else {
112+
deprecate(
113+
() => Object.assign(customized, fastbootTestConfig),
114+
`Exporting an object from ${fastbootTestConfigPath} has been deprecated. Please export a function which returns an object instead.`
115+
)();
116+
}
117+
}
106118

107119
return Object.assign({}, config, defaults, customized);
108120
}

tests/dummy/app/templates/docs/fastboot-configuration.md

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,17 @@ When using this addon a new FastBoot instance will be created specifically for t
55
```js
66
// my-app/config/fastboot-tesitng.js
77

8-
module.exports = {
9-
resilient: true,
10-
buildSandboxGlobals(defaultGlobals) {
11-
return Object.assign({}, defaultGlobals, {
12-
SampleGlobal: `TestSampleGlobal`,
13-
najax
14-
});
15-
}
8+
module.exports = () => {
9+
return {
10+
resilient: true,
11+
buildSandboxGlobals(defaultGlobals) {
12+
return {
13+
...defaultGlobals,
14+
SampleGlobal: `TestSampleGlobal`,
15+
najax,
16+
};
17+
},
18+
};
1619
};
1720
```
1821

tests/dummy/config/fastboot-testing.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,15 @@ if (semver.lt(version, '3.0.0')) {
1111
},
1212
};
1313
} else {
14-
module.exports = {
15-
resilient: false,
16-
buildSandboxGlobals(defaultGlobals) {
17-
return Object.assign({}, defaultGlobals, {
18-
SampleGlobal: 'TestSampleGlobal',
19-
najax,
20-
});
21-
},
14+
module.exports = () => {
15+
return {
16+
resilient: false,
17+
buildSandboxGlobals(defaultGlobals) {
18+
return Object.assign({}, defaultGlobals, {
19+
SampleGlobal: 'TestSampleGlobal',
20+
najax,
21+
});
22+
},
23+
};
2224
};
2325
}

0 commit comments

Comments
 (0)