-
Notifications
You must be signed in to change notification settings - Fork 18
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
[WIP] Expose nock
via comlink
#61
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,13 +15,15 @@ | |
}, | ||
"scripts": { | ||
"build": "ember build", | ||
"install": "cd node_modules/comlink && npm install && npm run build", | ||
"lint:js": "eslint .", | ||
"start": "ember serve", | ||
"test": "ember test", | ||
"test:all": "ember try:each" | ||
}, | ||
"dependencies": { | ||
"body-parser": "^1.18.3", | ||
"comlink": "CvX/comlink#wrap-chain", | ||
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. I know you added some stuff here to get the chaning working. Should we wait for them to merge it or depend on this branch? 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. Continuing from the previous comment: I wouldn’t use this setup. I’d either wait for a comlink release or, in case that gets stuck, I’d push a fork of comlink with chain method calls to npm. |
||
"ember-auto-import": "^1.2.15", | ||
"ember-cli-babel": "^6.6.0", | ||
"fastboot": "^1.2.1", | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
import { module, test } from 'qunit'; | ||
import { setup, visit, nock } from 'ember-cli-fastboot-testing/test-support'; | ||
|
||
module('Fastboot | nock proxy', function(hooks) { | ||
setup(hooks); | ||
|
||
test('it will not change an endpoint that already exists', async function(assert) { | ||
await visit('/examples/network/other/echo?message=hello%20world'); | ||
assert.dom('[data-test-id="echo"]').hasText("hello world"); | ||
}); | ||
|
||
test('it can mock an array of models', async function(assert) { | ||
await nock('http://localhost:7357') | ||
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. Is it possible to auto detect the local hostname and not require it here? 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. We could set the |
||
.intercept('/api/notes', 'GET') | ||
.reply(200, { | ||
data: [ | ||
{ | ||
type: 'note', | ||
id: '1', | ||
attributes: { | ||
title: 'test note' | ||
} | ||
}, | ||
{ | ||
type: 'note', | ||
id: '2', | ||
attributes: { | ||
title: 'test 2' | ||
} | ||
} | ||
] | ||
}); | ||
|
||
await visit('/examples/network/notes'); | ||
|
||
assert.dom('[data-test-id="title-1"]').hasText("test note") | ||
assert.dom('[data-test-id="title-2"]').hasText("test 2") | ||
}); | ||
|
||
test('it can mock a single model', async function(assert) { | ||
await nock('http://localhost:7357') | ||
.intercept('/api/notes/1', 'GET') | ||
.reply(200, { | ||
data: { | ||
type: "notes", | ||
id: "1", | ||
attributes: { | ||
title: 'test note' | ||
} | ||
} | ||
}); | ||
|
||
await visit('/examples/network/notes/1'); | ||
|
||
assert.dom('[data-test-id="title"]').hasText("test note"); | ||
}); | ||
|
||
test('it can mock 404s', async function(assert) { | ||
await nock('http://localhost:7357') | ||
.intercept('/api/notes/1', 'GET') | ||
.reply(404, { | ||
errors: [ | ||
{ title: "Not found" } | ||
] | ||
}); | ||
|
||
await visit('/examples/network/notes/1'); | ||
|
||
assert.dom().includesText('Ember Data Request GET /api/notes/1 returned a 404'); | ||
}); | ||
|
||
test('it can mock a get request', async function(assert) { | ||
await nock('http://localhost:7357') | ||
.intercept('/api/notes', 'GET') | ||
.reply(200, [ | ||
{ id: 1, title: 'get note' }, | ||
]); | ||
|
||
await visit('/examples/network/other/get-request'); | ||
|
||
assert.dom('[data-test-id="title-1"]').hasText("get note") | ||
}); | ||
|
||
test('it can mock a post request', async function(assert) { | ||
await nock('http://localhost:7357') | ||
.intercept('/api/notes', 'POST') | ||
.reply(200, [ | ||
{ id: 1, title: 'post note' }, | ||
]); | ||
|
||
await visit('/examples/network/other/post-request'); | ||
|
||
assert.dom('[data-test-id="title-1"]').hasText("post note") | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3663,6 +3663,10 @@ combined-stream@~0.0.4: | |
dependencies: | ||
delayed-stream "0.0.5" | ||
|
||
comlink@CvX/comlink#wrap-chain: | ||
version "4.0.1" | ||
resolved "https://codeload.github.com/CvX/comlink/tar.gz/f7913e3a02905389eeee4fda441356f3dbb19688" | ||
|
||
[email protected]: | ||
version "2.12.2" | ||
resolved "https://registry.yarnpkg.com/commander/-/commander-2.12.2.tgz#0f5946c427ed9ec0d91a46bb9def53e54650e555" | ||
|
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.
Does comlink need to be compiled? Does this have any negatives or gotchas?
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.
Yeah, the compile step is necessary when using the git repo source. Comlink’s written in TypeScript, and gets compiled to JS when published to npm, so here we need to do it on our own.
It’s just a temporary solution for sharing this work-in-progress. I wouldn’t even try publishing ECFT with it. 😅
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.
Ah cool, good to know