Skip to content

Commit

Permalink
Fix Ember Data najax errors (#240)
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanto authored Jan 15, 2020
1 parent 019b63c commit 0a77bbc
Show file tree
Hide file tree
Showing 6 changed files with 2,697 additions and 2,934 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ language: node_js
sudo: false
dist: trusty
node_js:
- "8"
- "10"

addons:
chrome: stable
Expand Down
86 changes: 46 additions & 40 deletions config/ember-try.js
Original file line number Diff line number Diff line change
@@ -1,95 +1,101 @@
'use strict';
"use strict";

const getChannelURL = require('ember-source-channel-url');
const getChannelURL = require("ember-source-channel-url");

module.exports = function() {
return Promise.all([
getChannelURL('release'),
getChannelURL('beta'),
getChannelURL('canary')
]).then((urls) => {
getChannelURL("release"),
getChannelURL("beta"),
getChannelURL("canary")
]).then(urls => {
return {
useYarn: true,
scenarios: [
{
name: 'ember-lts-2.8',
bower: {
dependencies: {
'ember': 'components/ember#lts-2-8'
},
resolutions: {
'ember': 'lts-2-8'
}
},
npm: {
devDependencies: {
'ember-source': null,
'ember-cli-head': '0.3.1'
}
}
},
{
name: 'ember-lts-2.18',
name: "ember-lts-2.18",
npm: {
devDependencies: {
'ember-source': '~2.18.0'
"ember-source": "~2.18.0",
"ember-data": "~2.18.0"
}
}
},
{
name: 'ember-lts-3.4',
name: "ember-lts-3.4",
npm: {
devDependencies: {
'ember-source': '~3.4.0'
"ember-source": "~3.4.0",
"ember-data": "~3.4.0"
}
}
},
{
name: 'ember-lts-3.8',
name: "ember-lts-3.8",
npm: {
devDependencies: {
'ember-source': '~3.8.0'
"ember-source": "~3.8.0",
"ember-data": "~3.8.0"
}
}
},
{
name: 'ember-lts-3.12',
name: "ember-lts-3.12",
npm: {
devDependencies: {
'ember-source': '~3.12.0'
"ember-source": "~3.12.0",
"ember-data": "~3.12.0"
},
resolutions: {
"ember-data": "~3.12.0"
}
}
},
{
name: 'fastboot-1.2',
name: "fastboot-1.2",
npm: {
devDependencies: {
'ember-source': '~3.4.0',
'fastboot': '~1.2.0'
"ember-source": "~3.4.0",
"ember-data": "~3.4.0",
fastboot: "~1.2.0"
}
}
},
{
name: 'ember-release',
name: "ember-release",
npm: {
devDependencies: {
'ember-source': urls[0]
"ember-source": urls[0],
// at the time of writing this the current 'latest' of ember-data is
// 3.15, which is broken in fastboot. we're going to use 3.13 since it's
// the closest working version
"ember-data": "~3.13.0"
},
resolutions: {
"ember-data": "~3.13.0"
}
}
},
{
name: 'ember-beta',
name: "ember-beta",
npm: {
devDependencies: {
'ember-source': urls[1]
"ember-source": urls[1],
"ember-data": "beta"
},
resolutions: {
"ember-data": "beta"
}
}
},
{
name: 'ember-canary',
name: "ember-canary",
npm: {
devDependencies: {
'ember-source': urls[2]
"ember-source": urls[2],
"ember-data": "canary"
},
resolutions: {
"ember-data": "canary"
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"broccoli-plugin": "^3.0.0",
"broccoli-stew": "^3.0.0",
"ember-cli": "~3.1.4",
"ember-cli-addon-docs": "0.6.14",
"ember-cli-addon-docs": "0.6.16",
"ember-cli-addon-docs-yuidoc": "^0.2.1",
"ember-cli-dependency-checker": "^3.2.0",
"ember-cli-deploy": "^1.0.2",
Expand All @@ -48,13 +48,13 @@
"ember-cli-fastboot": "^2.1.1",
"ember-cli-head": "^0.4.1",
"ember-cli-htmlbars": "^4.0.1",
"ember-cli-htmlbars-inline-precompile": "^3.0.0",
"ember-cli-inject-live-reload": "^2.0.1",
"ember-cli-mirage": "^1.1.0-beta.2",
"ember-cli-qunit": "^4.3.2",
"ember-cli-shims": "^1.2.0",
"ember-cli-sri": "^2.1.0",
"ember-cli-uglify": "^3.0.0",
"ember-data": "~3.2.0",
"ember-disable-prototype-extensions": "^1.1.2",
"ember-export-application-global": "^2.0.0",
"ember-fetch": "^7.0.0",
Expand Down
6 changes: 2 additions & 4 deletions tests/dummy/app/pods/examples/network/notes/index/route.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import Route from '@ember/routing/route';
import Route from "@ember/routing/route";

export default Route.extend({

async model() {
return this.store.findAll('note');
return this.store.findAll("note");
}

});
90 changes: 44 additions & 46 deletions tests/fastboot/network-mocking-test.js
Original file line number Diff line number Diff line change
@@ -1,100 +1,98 @@
import { module, test } from 'qunit';
import { setup, visit, mockServer } from 'ember-cli-fastboot-testing/test-support';

module('Fastboot | network mocking', function(hooks) {
import { module, test } from "qunit";
import {
setup,
visit,
mockServer
} from "ember-cli-fastboot-testing/test-support";

module("Fastboot | network mocking", 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');
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 mockServer.get('/api/notes', {
test("it can mock an array of models", async function(assert) {
await mockServer.get("/api/notes", {
data: [
{
type: 'note',
id: '1',
type: "note",
id: "1",
attributes: {
title: 'test note'
title: "test note"
}
},
{
type: 'note',
id: '2',
type: "note",
id: "2",
attributes: {
title: 'test 2'
title: "test 2"
}
}
]
});

await visit('/examples/network/notes');
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")
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 mockServer.get('/api/notes/1', {
test("it can mock a single model", async function(assert) {
await mockServer.get("/api/notes/1", {
data: {
type: "note",
id: "1",
attributes: {
title: 'test note'
title: "test note"
}
}
});

await visit('/examples/network/notes/1');
await visit("/examples/network/notes/1");

assert.dom('[data-test-id="title"]').hasText("test note");
});

test('it can mock 404s', async function(assert) {
test("it can mock 404s", async function(assert) {
await mockServer.get(
'/api/notes/1',
"/api/notes/1",
{
errors: [
{ title: "Not found" }
]
errors: [{ title: "Not found" }]
},
404
);

await visit('/examples/network/notes/1');
await visit("/examples/network/notes/1");

assert.dom().includesText('Ember Data Request GET /api/notes/1 returned a 404');
assert
.dom()
.includesText("Ember Data Request GET /api/notes/1 returned a 404");
});

test('it can mock a get request', async function(assert) {
await mockServer.get('/api/notes', [
{ id: 1, title: 'get note'},
]);
test("it can mock a get request", async function(assert) {
await mockServer.get("/api/notes", [{ id: 1, title: "get note" }]);

await visit('/examples/network/other/get-request');
await visit("/examples/network/other/get-request");

assert.dom('[data-test-id="title-1"]').hasText("get note")
assert.dom('[data-test-id="title-1"]').hasText("get note");
});

test('it can mock a post request', async function(assert) {
await mockServer.post('/api/notes', [
{ id: 1, title: 'post note'},
]);
test("it can mock a post request", async function(assert) {
await mockServer.post("/api/notes", [{ id: 1, title: "post note" }]);

await visit('/examples/network/other/post-request');
await visit("/examples/network/other/post-request");

assert.dom('[data-test-id="title-1"]').hasText("post note")
assert.dom('[data-test-id="title-1"]').hasText("post note");
});

test('it can mock a large response', async function(assert) {
let title = 'a'.repeat(1024 * 1024 * 5); // 5 MB
test("it can mock a large response", async function(assert) {
let title = "a".repeat(1024 * 1024 * 5); // 5 MB

await mockServer.get('/api/notes', [
{ id: 1, title },
]);
await mockServer.get("/api/notes", [{ id: 1, title }]);

await visit('/examples/network/other/get-request');
await visit("/examples/network/other/get-request");

assert.dom('[data-test-id="title-1"]').exists();
});
Expand Down
Loading

0 comments on commit 0a77bbc

Please sign in to comment.