This repository has been archived by the owner on May 17, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 17
Implement wrapper in fusion-test-utils
to encapsulate plugin resolution
#38
Merged
AlexMSmithCA
merged 9 commits into
fusionjs:master
from
AlexMSmithCA:function-to-encapsulate-resolve
Jan 16, 2018
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
8ba7a6b
Added Flow types
AlexMSmithCA 49a881d
Implement 'registerAsTest' which returns request and render
AlexMSmithCA ce5cda5
Update unit tests to leverage 'registerAsTest'
AlexMSmithCA 791a223
Test plugin resolution with dependency injection
AlexMSmithCA 0ed13c8
Use registry.yarnpkg.com instead of internal registry
AlexMSmithCA 517fd34
Added a test fixture example for registerAsTest
AlexMSmithCA aca89cd
Rename 'registerAsTest' to 'getSimulator' for clarity-sake
AlexMSmithCA 5b3323d
Update documentation
AlexMSmithCA eedcc92
Merge remote-tracking branch 'upstream/master' into function-to-encap…
AlexMSmithCA File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,15 @@ | ||
[ignore] | ||
.*/node_modules/.*[^(package)]\.json$ | ||
<PROJECT_ROOT>/dist/.* | ||
|
||
[include] | ||
./src/ | ||
|
||
[libs] | ||
./node_modules/fusion-core/flow-typed | ||
|
||
[lints] | ||
|
||
[options] | ||
suppress_comment= \\(.\\|\n\\)*\\$FlowIgnore | ||
|
||
[strict] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,62 @@ | ||
//@flow | ||
|
||
import assert from 'assert'; | ||
|
||
import FusionApp from 'fusion-core'; | ||
import type {FusionPlugin} from 'fusion-core'; | ||
|
||
import {mockContext, renderContext} from './mock-context.js'; | ||
import simulate from './simulate'; | ||
|
||
export function request(app, url, options = {}) { | ||
declare var __BROWSER__: boolean; | ||
|
||
const request = (app: FusionApp) => ( | ||
url: string, | ||
options: * = {} | ||
): Promise<*> => { | ||
if (__BROWSER__) { | ||
throw new Error( | ||
'[fusion-test-utils] Request api not support from the browser. Please use `render` instead' | ||
); | ||
} | ||
const ctx = mockContext(url, options); | ||
return simulate(app, ctx); | ||
} | ||
}; | ||
|
||
export function render(app, url, options = {}) { | ||
const render = (app: FusionApp) => ( | ||
url: string, | ||
options: * = {} | ||
): Promise<*> => { | ||
const ctx = renderContext(url, options); | ||
return simulate(app, ctx); | ||
}; | ||
|
||
export function getSimulator(app: FusionApp, testPlugin?: FusionPlugin<*, *>) { | ||
if (testPlugin) { | ||
app.register(testPlugin); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we allow for an array of test plugins? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is just the public API from the DI system. Whether multiple registration makes sense is something that we can discuss on Giancarlo's new proposal. |
||
} | ||
app.resolve(); | ||
|
||
return { | ||
request: request(app), | ||
render: render(app), | ||
}; | ||
} | ||
|
||
// Export test runner functions from jest | ||
// eslint-disable-next-line import/no-mutable-exports | ||
let mockFunction, test; | ||
// $FlowFixMe | ||
if (typeof it !== 'undefined') { | ||
// Surface snapshot testing | ||
// $FlowFixMe | ||
assert.matchSnapshot = tree => expect(tree).toMatchSnapshot(); | ||
|
||
/* eslint-env node, jest */ | ||
// $FlowFixMe | ||
test = (description, callback, ...rest) => | ||
it(description, () => callback(assert), ...rest); | ||
// $FlowFixMe | ||
mockFunction = (...args) => jest.fn(...args); | ||
} else { | ||
const notSupported = () => { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,9 @@ | ||
import {compose} from 'fusion-core'; | ||
// @flow | ||
|
||
export default function simulate(app, ctx) { | ||
app.resolve(); | ||
// $FlowFixMe | ||
import FusionApp, {compose} from 'fusion-core'; | ||
import type {Context} from 'fusion-core'; | ||
|
||
export default function simulate(app: FusionApp, ctx: Context): Promise<*> { | ||
return compose(app.plugins)(ctx, () => Promise.resolve()).then(() => ctx); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we using this for anything yet? Or just getting our configs to match?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good question- it's used here for
Context
andFusionApp
. At least internally, it looks like our plan is to shiplibdef
files like we are will soon be doing infusion-core
.