Skip to content

Commit 159d537

Browse files
committed
feat(config): adjust to expect a function rather than an object
More closely mirrors the config of `ember-cli-fastboot` itself and helps to avoid confusion.
1 parent 8612da4 commit 159d537

4 files changed

Lines changed: 46 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: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,18 @@ function makeFastbootTestingConfig(config, pkg) {
100100
'fastboot-testing.js'
101101
);
102102

103-
const customized = fs.existsSync(fastbootTestConfigPath)
104-
? require(fastbootTestConfigPath)
105-
: {};
103+
let customized = {};
104+
105+
if (fs.existsSync(fastbootTestConfigPath)) {
106+
const fastbootTestConfig = require(fastbootTestConfigPath);
107+
if (typeof fastbootTestConfig !== 'function') {
108+
throw new Error(
109+
`Expected export of ${fastbootTestConfigPath} to be a function. Instead found (${typeof fastbootTestConfig}).`
110+
);
111+
}
112+
113+
customized = fastbootTestConfig();
114+
}
106115

107116
return Object.assign({}, config, defaults, customized);
108117
}

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)