Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Config exports function rather than object #762

Merged
merged 4 commits into from
Mar 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
module.exports = {
resilient: false,
sandboxGlobals: {},
setupFastboot: fastbootInstance => {
// here you can access the fastboot instance which runs the tests
}
module.exports = () => {
return {
resilient: false,
buildSandboxGlobals(defaultGlobals) {
return {
...defaultGlobals
// here you can add globals to the Fastboot renderer
};
},
setupFastboot(fastbootInstance) {
// here you can access the fastboot instance which runs the tests
},
};
};
18 changes: 15 additions & 3 deletions lib/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const { URL } = require('url');
const JSONfn = require('json-fn');
const FastBoot = require('fastboot');
const bodyParser = require('body-parser');
const { deprecate } = require('util');

function createMockRequest(app) {
app.post(
Expand Down Expand Up @@ -100,9 +101,20 @@ function makeFastbootTestingConfig(config, pkg) {
'fastboot-testing.js'
);

const customized = fs.existsSync(fastbootTestConfigPath)
? require(fastbootTestConfigPath)
: {};
let customized = {};

if (fs.existsSync(fastbootTestConfigPath)) {
const fastbootTestConfig = require(fastbootTestConfigPath);

if (typeof fastbootTestConfig === 'function') {
customized = fastbootTestConfig();
} else {
deprecate(
() => Object.assign(customized, fastbootTestConfig),
`Exporting an object from ${fastbootTestConfigPath} has been deprecated. Please export a function which returns an object instead.`
)();
}
}

return Object.assign({}, config, defaults, customized);
}
Expand Down
19 changes: 11 additions & 8 deletions tests/dummy/app/templates/docs/fastboot-configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,17 @@ When using this addon a new FastBoot instance will be created specifically for t
```js
// my-app/config/fastboot-tesitng.js

module.exports = {
resilient: true,
buildSandboxGlobals(defaultGlobals) {
return Object.assign({}, defaultGlobals, {
SampleGlobal: `TestSampleGlobal`,
najax
});
}
module.exports = () => {
return {
resilient: true,
buildSandboxGlobals(defaultGlobals) {
return {
...defaultGlobals,
SampleGlobal: `TestSampleGlobal`,
najax,
};
},
};
};
```

Expand Down
18 changes: 10 additions & 8 deletions tests/dummy/config/fastboot-testing.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@ if (semver.lt(version, '3.0.0')) {
},
};
} else {
module.exports = {
resilient: false,
buildSandboxGlobals(defaultGlobals) {
return Object.assign({}, defaultGlobals, {
SampleGlobal: 'TestSampleGlobal',
najax,
});
},
module.exports = () => {
return {
resilient: false,
buildSandboxGlobals(defaultGlobals) {
return Object.assign({}, defaultGlobals, {
SampleGlobal: 'TestSampleGlobal',
najax,
});
},
};
};
}