Created
March 22, 2022 07:50
-
-
Save al3xnag/4da2dc6812e1597904436681abc62f47 to your computer and use it in GitHub Desktop.
ed race cond
This file contains hidden or 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
import Controller from '@ember/controller'; | |
import { inject as service } from '@ember/service'; | |
export default class ApplicationController extends Controller { | |
appName = 'Ember Twiddle'; | |
} |
This file contains hidden or 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
import Model from 'ember-data/model'; | |
import attr from 'ember-data/attr'; | |
import { belongsTo, hasMany } from 'ember-data/relationships'; | |
export default class extends Model { | |
@attr('string') title; | |
} |
This file contains hidden or 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
import Application from '../app'; | |
import config from '../config/environment'; | |
import { setApplication } from '@ember/test-helpers'; | |
import { assign } from '@ember/polyfills'; | |
import { start } from 'ember-qunit'; | |
let attributes = { | |
rootElement: '#test-root', | |
autoboot: false | |
}; | |
attributes = assign(attributes, config.APP); | |
let application = Application.create(attributes); | |
setApplication(application); | |
start(); |
This file contains hidden or 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
import { module, test } from 'qunit'; | |
import { setupTest } from 'ember-qunit'; | |
import Pretender from 'pretender'; | |
module('TODO: put something here', function(hooks) { | |
setupTest(hooks); | |
test('services/store/with-socks :: race condition: no ember-data issue', async function(assert) { | |
const store = this.owner.lookup('service:store'); | |
const socksPublishContext = { | |
channel: 'system', | |
data: '{"courses": [{"id": "1", "title": "test course 1"}]}', | |
}; | |
const serverResponse = [ | |
201, | |
{ 'Content-Type': 'application/json' }, | |
JSON.stringify({ | |
courses: [{ id: 1, title: 'test course 1' }] | |
}) | |
]; | |
let courseViaRest; | |
let courseViaWS; | |
const server = new Pretender(function() { | |
this.post('/api/courses', (req) => { | |
return new Promise(resolve => { | |
//socks.onPublish(socksPublishContext); | |
store.pushPayload('course', { | |
courses: [{ id: 1, title: 'test course 1' }] | |
}); | |
courseViaWS = store.peekRecord('course', 1); | |
assert.equal(courseViaWS.id, '1'); | |
assert.equal(courseViaWS.title, 'test course 1'); | |
assert.equal(courseViaWS.isLoaded, true); | |
assert.equal(courseViaWS.isSaving, false); | |
assert.ok(courseViaRest); | |
assert.notEqual(courseViaRest, courseViaWS); | |
assert.equal(courseViaRest.isSaving, true); | |
assert.equal(courseViaRest.id, null); | |
setTimeout(() => resolve(serverResponse), 100); | |
}); | |
}); | |
}); | |
try { | |
courseViaRest = store.createRecord('course', { title: 'test course 1' }); | |
await courseViaRest.save(); | |
assert.equal(courseViaRest.id, '1'); | |
assert.equal(courseViaRest.title, 'test course 1'); | |
assert.equal(courseViaRest.isLoaded, true); | |
assert.notEqual(courseViaRest, courseViaWS); | |
assert.equal(courseViaWS.id, '1'); | |
assert.equal(courseViaWS.title, 'test course 1'); | |
} finally { | |
server.shutdown(); | |
} | |
}); | |
}); |
This file contains hidden or 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
{ | |
"version": "0.17.1", | |
"EmberENV": { | |
"FEATURES": {}, | |
"_TEMPLATE_ONLY_GLIMMER_COMPONENTS": false, | |
"_APPLICATION_TEMPLATE_WRAPPER": true, | |
"_JQUERY_INTEGRATION": true | |
}, | |
"options": { | |
"use_pods": false, | |
"enable-testing": true | |
}, | |
"dependencies": { | |
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.js", | |
"ember": "3.4.3", | |
"ember-template-compiler": "3.4.3", | |
"ember-testing": "3.4.3" | |
}, | |
"addons": { | |
"@glimmer/component": "1.0.0", | |
"ember-data": "3.4.2", | |
"ember-cli-pretender": "^3.1.1" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment