diff --git a/.bowerrc b/.bowerrc deleted file mode 100644 index 959e169..0000000 --- a/.bowerrc +++ /dev/null @@ -1,4 +0,0 @@ -{ - "directory": "bower_components", - "analytics": false -} diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 0000000..29c9bc6 --- /dev/null +++ b/.eslintignore @@ -0,0 +1,23 @@ +# See https://help.github.com/ignore-files/ for more about ignoring files. + +# compiled output +/dist/ +/tmp/ + +# dependencies +/bower_components/ +/node_modules/ + +# misc +/.sass-cache +/connect.lock +/coverage/ +/libpeerconnection.log +/npm-debug.log* +/testem.log +/yarn-error.log + +# ember-try +/.node_modules.ember-try/ +/bower.json.ember-try +/package.json.ember-try diff --git a/.eslintrc.js b/.eslintrc.js index f401e3b..b94c535 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -7,10 +7,48 @@ module.exports = { ecmaVersion: 2017, sourceType: 'module' }, - extends: 'eslint:recommended', + plugins: [ + 'ember' + ], + extends: [ + 'eslint:recommended', + 'plugin:ember/recommended' + ], env: { browser: true }, rules: { - } + }, + overrides: [ + // node files + { + files: [ + '.template-lintrc.js', + 'ember-cli-build.js', + 'index.js', + 'testem.js', + 'blueprints/*/index.js', + 'config/**/*.js', + 'tests/dummy/config/**/*.js' + ], + excludedFiles: [ + 'addon/**', + 'addon-test-support/**', + 'app/**', + 'tests/dummy/app/**' + ], + parserOptions: { + sourceType: 'script', + ecmaVersion: 2015 + }, + env: { + browser: false, + node: true + }, + plugins: ['node'], + rules: Object.assign({}, require('eslint-plugin-node').configs.recommended.rules, { + // add your custom rules and overrides for node files here + }) + } + ] }; diff --git a/.gitignore b/.gitignore index 5ad14dd..29c9bc6 100644 --- a/.gitignore +++ b/.gitignore @@ -1,17 +1,23 @@ # See https://help.github.com/ignore-files/ for more about ignoring files. # compiled output -/dist -/tmp +/dist/ +/tmp/ # dependencies -/node_modules -/bower_components +/bower_components/ +/node_modules/ # misc /.sass-cache /connect.lock -/coverage/* +/coverage/ /libpeerconnection.log -npm-debug.log* -testem.log +/npm-debug.log* +/testem.log +/yarn-error.log + +# ember-try +/.node_modules.ember-try/ +/bower.json.ember-try +/package.json.ember-try diff --git a/.npmignore b/.npmignore index 889b2bf..f4a79da 100644 --- a/.npmignore +++ b/.npmignore @@ -7,10 +7,16 @@ .bowerrc .editorconfig .ember-cli -.gitignore .eslintrc.js +.gitignore .watchmanconfig .travis.yml bower.json ember-cli-build.js testem.js +yarn.lock + +# ember-try +.node_modules.ember-try/ +bower.json.ember-try +package.json.ember-try diff --git a/.template-lintrc.js b/.template-lintrc.js new file mode 100644 index 0000000..b45e96f --- /dev/null +++ b/.template-lintrc.js @@ -0,0 +1,5 @@ +'use strict'; + +module.exports = { + extends: 'recommended' +}; diff --git a/.travis.yml b/.travis.yml index 21bbdc4..c9e48c6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,26 +1,34 @@ --- language: node_js node_js: + # we recommend testing addons with the same minimum supported node version as Ember CLI + # so that your addon works for all apps - "6" -sudo: required +sudo: false dist: trusty addons: chrome: stable cache: - yarn: true + directories: + - $HOME/.npm env: - # we recommend new addons test the current and previous LTS - # as well as latest stable release (bonus points to beta/canary) - - EMBER_TRY_SCENARIO=ember-lts-2.8 - - EMBER_TRY_SCENARIO=ember-lts-2.12 - - EMBER_TRY_SCENARIO=ember-release - - EMBER_TRY_SCENARIO=ember-beta - - EMBER_TRY_SCENARIO=ember-canary - - EMBER_TRY_SCENARIO=ember-default + global: + # See https://git.io/vdao3 for details. + - JOBS=1 + matrix: + # we recommend new addons test the current and previous LTS + # as well as latest stable release (bonus points to beta/canary) + - EMBER_TRY_SCENARIO=ember-lts-2.12 + - EMBER_TRY_SCENARIO=ember-lts-2.16 + - EMBER_TRY_SCENARIO=ember-lts-2.18 + - EMBER_TRY_SCENARIO=ember-release + - EMBER_TRY_SCENARIO=ember-beta + - EMBER_TRY_SCENARIO=ember-canary + - EMBER_TRY_SCENARIO=ember-default matrix: fast_finish: true @@ -28,15 +36,12 @@ matrix: - env: EMBER_TRY_SCENARIO=ember-canary before_install: - - curl -o- -L https://yarnpkg.com/install.sh | bash - - export PATH=$HOME/.yarn/bin:$PATH - - "sudo chown root /opt/google/chrome/chrome-sandbox" - - "sudo chmod 4755 /opt/google/chrome/chrome-sandbox" - -install: - - yarn install --no-lockfile --non-interactive + - npm config set spin false + - npm install -g npm@4 + - npm --version script: + - npm run lint:js # Usually, it's ok to finish the test scenario without reverting # to the addon's original dependency state, skipping "cleanup". - node_modules/.bin/ember try:one $EMBER_TRY_SCENARIO --skip-cleanup diff --git a/CHANGELOG.md b/CHANGELOG.md deleted file mode 100644 index a0a0197..0000000 --- a/CHANGELOG.md +++ /dev/null @@ -1,69 +0,0 @@ -# Changelog - -All notable changes to this project will be documented in this file. - -The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) -and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). - -## Unreleased - -### Added - -- Support for nested queries (#43) - -## [0.4.0] - 2017-09-04 - -### Added - -- Support for relationship urlTemplates (#36) - -## [0.3.1] - 2017-07-06 - -### Added - -- Automatic support for attributes from the snapshot (#34) -- Automatic support for relationship ids from the snapshot (#34) -- Acceptance Tests!!! - -## [0.3.0] - 2017-06-19 - -### Fixed - -- Clear null and remove undefined values from query parameters (#23) - -### Changed - -- Update ember-cli to 2.13.2 - -## [0.2.0] - 2016-09-27 - -### Fixed - -- Prevent double query params (#19) - -## [0.1.1] - 2016-04-29 - -### Fixed - -- Don't double URI-encode IDs (#14) - -### Changed - -- Pull uri-templates from npm instead of Bower (#18) - -## [0.1.0] - 2015-12-18 - -### Added - -- Ensures that the native urlSegments isn't overwritten (#5) -- Fall back to original buildURL if no template is found (#6) - -### Changed - -- Update ember-cli (#9) - -### Removed - -- Remove support for Ember Data 1.0.0-beta.17 (ad3e03a6ddf38a1efa2afc668fd31b1dac806343) -- Remove re-implentation of default pathForType() (#10) - diff --git a/LICENSE.md b/LICENSE.md index 00e9fbb..198f6da 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2015 +Copyright (c) 2018 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: diff --git a/addon/mixins/url-templates-serializer.js b/addon/mixins/url-templates-serializer.js index e65ad3f..fbc2bae 100644 --- a/addon/mixins/url-templates-serializer.js +++ b/addon/mixins/url-templates-serializer.js @@ -1,10 +1,9 @@ -import Ember from 'ember'; - -const { get } = Ember; +import { get } from '@ember/object'; +import Mixin from '@ember/object/mixin'; export const LINK_PREFIX = 'urlTemplate:'; -export default Ember.Mixin.create({ +export default Mixin.create({ normalize(modelClass) { let result = this._super(...arguments); return _injectLinksForRelationships(modelClass, result); diff --git a/addon/mixins/url-templates.js b/addon/mixins/url-templates.js index 123c0f9..8cc3fb4 100644 --- a/addon/mixins/url-templates.js +++ b/addon/mixins/url-templates.js @@ -1,15 +1,16 @@ -import Ember from 'ember'; +import { isArray } from '@ember/array'; +import { typeOf } from '@ember/utils'; +import Mixin from '@ember/object/mixin'; +import EmberObject from '@ember/object'; import UriTemplate from 'uri-templates'; import { assign } from '@ember/polyfills'; import { LINK_PREFIX } from "ember-data-url-templates/mixins/url-templates-serializer"; import flattenQueryParams from 'ember-data-url-templates/utils/flatten-query-params'; -const { isArray, typeOf } = Ember; - const ID_KEY_RE = /(_id|Id)$/; const LINK_PREFIX_RE = new RegExp(`^${LINK_PREFIX}`); -export default Ember.Mixin.create({ +export default Mixin.create({ mergedProperties: ['urlSegments'], buildURL(type, id, snapshot, requestType, query) { const templateString = this.getTemplate(requestType); @@ -54,7 +55,7 @@ export default Ember.Mixin.create({ // TODO: Add ability to customize templateResolver // TODO: Add reference to the adapter templateResolverFor(/* type */) { - return Ember.Object.create(this.get('urlSegments')); + return EmberObject.create(this.get('urlSegments')); }, // HACK: Prevent query/queryRecord from appending query params to urls, we diff --git a/config/ember-try.js b/config/ember-try.js index 21f6079..644b02b 100644 --- a/config/ember-try.js +++ b/config/ember-try.js @@ -1,83 +1,70 @@ -/* eslint-env node */ -module.exports = { - scenarios: [ - { - name: 'ember-lts-2.8', - bower: { - dependencies: { - 'ember': 'components/ember#lts-2-8' +'use strict'; + +const getChannelURL = require('ember-source-channel-url'); + +module.exports = function() { + return Promise.all([ + getChannelURL('release'), + getChannelURL('beta'), + getChannelURL('canary') + ]).then((urls) => { + return { + scenarios: [ + { + name: 'ember-lts-2.12', + npm: { + devDependencies: { + 'ember-source': '~2.12.0' + } + } }, - resolutions: { - 'ember': 'lts-2-8' - } - }, - npm: { - devDependencies: { - 'ember-source': null - } - } - }, - { - name: 'ember-lts-2.12', - npm: { - devDependencies: { - 'ember-source': '~2.12.0' - } - } - }, - { - name: 'ember-release', - bower: { - dependencies: { - 'ember': 'components/ember#release' + { + name: 'ember-lts-2.16', + npm: { + devDependencies: { + 'ember-source': '~2.16.0' + } + } }, - resolutions: { - 'ember': 'release' - } - }, - npm: { - devDependencies: { - 'ember-source': null - } - } - }, - { - name: 'ember-beta', - bower: { - dependencies: { - 'ember': 'components/ember#beta' + { + name: 'ember-lts-2.18', + npm: { + devDependencies: { + 'ember-source': '~2.18.0' + } + } }, - resolutions: { - 'ember': 'beta' - } - }, - npm: { - devDependencies: { - 'ember-source': null - } - } - }, - { - name: 'ember-canary', - bower: { - dependencies: { - 'ember': 'components/ember#canary' + { + name: 'ember-release', + npm: { + devDependencies: { + 'ember-source': urls[0] + } + } }, - resolutions: { - 'ember': 'canary' - } - }, - npm: { - devDependencies: { - 'ember-source': null + { + name: 'ember-beta', + npm: { + devDependencies: { + 'ember-source': urls[1] + } + } + }, + { + name: 'ember-canary', + npm: { + devDependencies: { + 'ember-source': urls[2] + } + } + }, + { + name: 'ember-default', + npm: { + devDependencies: {} + } } - } - }, - { - name: 'ember-default', - npm: { - devDependencies: {} - } - } - ] + ] + }; + }); }; diff --git a/config/environment.js b/config/environment.js index 012a412..0dfaed4 100644 --- a/config/environment.js +++ b/config/environment.js @@ -1,4 +1,3 @@ -/* eslint-env node */ 'use strict'; module.exports = function(/* environment, appConfig */) { diff --git a/ember-cli-build.js b/ember-cli-build.js index d6db8de..dc5a39e 100644 --- a/ember-cli-build.js +++ b/ember-cli-build.js @@ -1,11 +1,10 @@ -/* eslint-env node */ +'use strict'; + const EmberAddon = require('ember-cli/lib/broccoli/ember-addon'); module.exports = function(defaults) { - var app = new EmberAddon(defaults, { - 'ember-cli-babel': { - includePolyfill: true - }, + let app = new EmberAddon(defaults, { + // Add options here }); /* diff --git a/index.js b/index.js index 42e5e72..2e1d1d8 100644 --- a/index.js +++ b/index.js @@ -1,14 +1,5 @@ -/* eslint-env node */ 'use strict'; module.exports = { - name: 'ember-data-url-templates', - - options: { - nodeAssets: { - 'uri-templates': { - import: ['uri-templates.js'] - } - } - } + name: require('./package').name }; diff --git a/jsconfig.json b/jsconfig.json new file mode 100644 index 0000000..f408cac --- /dev/null +++ b/jsconfig.json @@ -0,0 +1 @@ +{"compilerOptions":{"target":"es6","experimentalDecorators":true},"exclude":["node_modules","bower_components","tmp","vendor",".git","dist"]} \ No newline at end of file diff --git a/package.json b/package.json index 93e68d2..ebdd679 100644 --- a/package.json +++ b/package.json @@ -14,39 +14,45 @@ "repository": "https://github.com/amiel/ember-data-url-templates", "scripts": { "build": "ember build", - "start": "ember server", - "test": "ember try:each" + "lint:js": "eslint .", + "start": "ember serve", + "test": "ember test", + "test:all": "ember try:each" }, "dependencies": { - "ember-cli-babel": "^6.0.0", + "ember-cli-babel": "^6.6.0", "ember-cli-uri-templates-shim": "^0.0.1" }, "devDependencies": { - "broccoli-asset-rev": "^2.4.5", + "broccoli-asset-rev": "^2.7.0", "ember-ajax": "^3.0.0", - "ember-chrome-devtools": "^0.1.1", - "ember-cli": "2.13.2", - "ember-cli-dependency-checker": "^1.3.0", - "ember-cli-eslint": "^3.0.0", - "ember-cli-htmlbars": "^1.1.1", - "ember-cli-htmlbars-inline-precompile": "^0.4.0", + "ember-cli": "~3.3.0", + "ember-cli-dependency-checker": "^2.0.0", + "ember-cli-eslint": "^4.2.1", + "ember-cli-htmlbars": "^2.0.1", + "ember-cli-htmlbars-inline-precompile": "^1.0.0", "ember-cli-inject-live-reload": "^1.4.1", - "ember-cli-mirage": "^0.3.3", - "ember-cli-qunit": "^4.0.0", - "ember-cli-shims": "^1.1.0", + "ember-cli-mirage": "^0.4.9", + "ember-cli-qunit": "^4.3.2", + "ember-cli-shims": "^1.2.0", "ember-cli-sri": "^2.1.0", - "ember-cli-uglify": "^1.2.0", - "ember-data": "^2.14.3", - "ember-disable-prototype-extensions": "^1.1.0", + "ember-cli-uglify": "^2.0.0", + "ember-data": "~3.5.0", + "ember-disable-prototype-extensions": "^1.1.2", "ember-export-application-global": "^2.0.0", - "ember-load-initializers": "^1.0.0", + "ember-load-initializers": "^1.1.0", + "ember-maybe-import-regenerator": "^0.1.6", "ember-resolver": "^4.0.0", - "ember-source": "~2.13.0", - "ember-welcome-page": "^3.0.0", - "loader.js": "^4.2.3" + "ember-source": "~3.3.0", + "ember-source-channel-url": "^1.0.1", + "ember-try": "^0.2.23", + "eslint-plugin-ember": "^5.0.0", + "eslint-plugin-node": "^6.0.1", + "loader.js": "^4.2.3", + "qunit-dom": "^0.6.2" }, "engines": { - "node": ">= 4" + "node": "6.* || 8.* || >= 10.*" }, "ember-addon": { "configPath": "tests/dummy/config" diff --git a/testem.js b/testem.js index acf896d..726d187 100644 --- a/testem.js +++ b/testem.js @@ -1,19 +1,25 @@ -/* eslint-env node */ module.exports = { - "test_page": "tests/index.html?hidepassed", - "disable_watching": true, - launch_in_ci: [ + test_page: 'tests/index.html?hidepassed', + disable_watching: true, + launch_in_ci: [ 'Chrome' ], launch_in_dev: [ 'Chrome' ], - 'browser_args': { - 'Chrome': [ - '--disable-gpu', + browser_args: { + Chrome: { + ci: [ + // --no-sandbox is needed when running Chrome inside a container + process.env.CI ? '--no-sandbox' : null, '--headless', - '--remote-debugging-port=9222', + '--disable-gpu', + '--disable-dev-shm-usage', + '--disable-software-rasterizer', + '--mute-audio', + '--remote-debugging-port=0', '--window-size=1440,900' - ], + ].filter(Boolean) + } } }; diff --git a/tests/acceptance/basic-url-template-test.js b/tests/acceptance/basic-url-template-test.js index e560838..3ed749a 100644 --- a/tests/acceptance/basic-url-template-test.js +++ b/tests/acceptance/basic-url-template-test.js @@ -1,57 +1,53 @@ -import { test } from 'qunit'; -import moduleForAcceptance from '../../tests/helpers/module-for-acceptance'; +import { module, test } from 'qunit'; +import { visit, findAll, find } from '@ember/test-helpers'; +import { setupApplicationTest } from 'ember-qunit'; +import setupMirage from 'ember-cli-mirage/test-support/setup-mirage'; -moduleForAcceptance('Acceptance | basic url template'); +module('Acceptance | basic url template', function(hooks) { + setupApplicationTest(hooks); -test('it can use a simple custom url', function(assert) { - server.createList('post', 5); + setupMirage(hooks); - visit('/posts'); + test('it can use a simple custom url', async function(assert) { + server.createList('post', 5); - andThen(() => { - assert.equal(find('#posts .post').length, 5); + await visit('/posts'); + assert.equal(findAll('#posts .post').length, 5); }); -}); - -test('it can use a specific template for one type of call (queryRecord)', function(assert) { - server.create('post', { - slug: 'my-first-post', - title: 'This is my first post', - }); - - visit('/posts/my-first-post'); - - andThen(() => { - assert.equal(find('.post h2').text(), 'This is my first post'); - }); -}); + test('it can use a specific template for one type of call (queryRecord)', async function(assert) { + server.create('post', { + slug: 'my-first-post', + title: 'This is my first post', + }); -test('it can query with params', function(assert) { - server.create('post', { - id: 1, - slug: 'my-first-post', - title: 'This is my first post', + await visit('/posts/my-first-post'); + assert.equal(find('.post h2').innerText, 'This is my first post'); }); - server.create('post', { - id: 2, - slug: 'my-second-post', - title: 'This is my second post', - }); - - server.create('post', { - id: 3, - slug: 'my-third-post', - title: 'This is another post', - }); - - visit('/search/my'); - - andThen(() => { - assert.equal(find('#post-1').length, 1); - assert.equal(find('#post-2').length, 1); - assert.equal(find('#post-3').length, 0); + test('it can query with params', async function(assert) { + server.create('post', { + id: 1, + slug: 'my-first-post', + title: 'This is my first post', + }); + + server.create('post', { + id: 2, + slug: 'my-second-post', + title: 'This is my second post', + }); + + server.create('post', { + id: 3, + slug: 'my-third-post', + title: 'This is another post', + }); + + await visit('/search/my'); + + assert.equal(findAll('#post-1').length, 1); + assert.equal(findAll('#post-2').length, 1); + assert.equal(findAll('#post-3').length, 0); }); }); - diff --git a/tests/acceptance/simple-relationships-test.js b/tests/acceptance/simple-relationships-test.js index 94b1f83..373f16f 100644 --- a/tests/acceptance/simple-relationships-test.js +++ b/tests/acceptance/simple-relationships-test.js @@ -1,11 +1,15 @@ -import Ember from 'ember'; -import { test } from 'qunit'; -import moduleForAcceptance from '../../tests/helpers/module-for-acceptance'; +import { get } from '@ember/object'; +import { visit, findAll, find } from '@ember/test-helpers'; +import { module, test } from 'qunit'; +import { setupApplicationTest } from 'ember-qunit'; +import setupMirage from 'ember-cli-mirage/test-support/setup-mirage'; -const { get } = Ember; +module('Acceptance | simple relationships', async function(hooks) { + setupApplicationTest(hooks); -moduleForAcceptance('Acceptance | simple relationships', { - beforeEach() { + setupMirage(hooks); + + hooks.beforeEach(function () { this.author = server.create('author'); this.relatedPosts = server.createList('post', 2); @@ -22,36 +26,38 @@ moduleForAcceptance('Acceptance | simple relationships', { server.createList('reaction', 4, { post: this.post, }); - - visit(`/posts/${get(this.post, 'slug')}`); - }, -}); - -// The comments relationship comes with with data and ids. Therefore it uses -// the findRecord adapter hook in the comment adapter and the comment adapter -// urlTemplate. -test('it can use a belongsTo id from the snapshot when generating a url', function(assert) { - assert.equal(find('#comments p').length, 1); -}); - -// The reactions relationshp is configured in the post model to use the -// urlTemplate. It therefore uses the findMany hook in the post adapter and -// the post adapter reactionsUrlTemplate. -test('it can load a hasMany relationship from just a url template', function(assert) { - assert.equal(find('#reactions p').length, 4); -}); - -// The author relationshp is configured in the post model to use the -// urlTemplate. It therefore uses the findBelongsTo hook in the post adapter -// and the post adapter authorUrlTemplate. -test('it can load a belongsTo relationship from just a url template', function(assert) { - assert.equal(find('#author').text(), `by ${this.author.name}`); -}); - -// The relatedPosts relationship comes with links, and is a case to verify -// that including urlTemplates does not cause a regression in the default -// functionality for links. -test('it can load related posts through the normal links method', function(assert) { - assert.equal(find('#related-posts p').length, 2); + }); + + // The comments relationship comes with with data and ids. Therefore it uses + // the findRecord adapter hook in the comment adapter and the comment adapter + // urlTemplate. + test('it can use a belongsTo id from the snapshot when generating a url', async function(assert) { + await visit(`/posts/${get(this.post, 'slug')}`); + assert.equal(findAll('#comments p').length, 1); + }); + + // The reactions relationshp is configured in the post model to use the + // urlTemplate. It therefore uses the findMany hook in the post adapter and + // the post adapter reactionsUrlTemplate. + test('it can load a hasMany relationship from just a url template', async function(assert) { + await visit(`/posts/${get(this.post, 'slug')}`); + assert.equal(findAll('#reactions p').length, 4); + }); + + // The author relationshp is configured in the post model to use the + // urlTemplate. It therefore uses the findBelongsTo hook in the post adapter + // and the post adapter authorUrlTemplate. + test('it can load a belongsTo relationship from just a url template', async function(assert) { + await visit(`/posts/${get(this.post, 'slug')}`); + assert.equal(find('#author').innerText, `by ${this.author.name}`); + }); + + // The relatedPosts relationship comes with links, and is a case to verify + // that including urlTemplates does not cause a regression in the default + // functionality for links. + test('it can load related posts through the normal links method', async function(assert) { + await visit(`/posts/${get(this.post, 'slug')}`); + assert.equal(findAll('#related-posts p').length, 2); + }); }); diff --git a/tests/acceptance/using-attributes-test.js b/tests/acceptance/using-attributes-test.js index 9cb8778..1d9e772 100644 --- a/tests/acceptance/using-attributes-test.js +++ b/tests/acceptance/using-attributes-test.js @@ -1,21 +1,22 @@ -import Ember from 'ember'; -import { test } from 'qunit'; -import moduleForAcceptance from '../../tests/helpers/module-for-acceptance'; +import { get } from '@ember/object'; +import { visit, click, findAll } from '@ember/test-helpers'; +import { module, test } from 'qunit'; +import { setupApplicationTest } from 'ember-qunit'; +import setupMirage from 'ember-cli-mirage/test-support/setup-mirage'; -const { get } = Ember; +module('Acceptance | using attributes', function(hooks) { + setupApplicationTest(hooks); -moduleForAcceptance('Acceptance | using attributes', { - beforeEach() { + setupMirage(hooks); + hooks.beforeEach(function () { this.post = server.create('post'); - }, -}); + }); -test('it can use an attribute from the snapshot when generating a url', function(assert) { - visit(`/posts/${get(this.post, 'slug')}`); - click('#publish-post'); - visit(`/posts/${get(this.post, 'slug')}`); + test('it can use an attribute from the snapshot when generating a url', async function(assert) { + await visit(`/posts/${get(this.post, 'slug')}`); + await click('#publish-post'); - andThen(() => { - assert.equal(find('#publish-post').length, 0); + await visit(`/posts/${get(this.post, 'slug')}`); + assert.equal(findAll('#publish-post').length, 0); }); }); diff --git a/tests/dummy/app/app.js b/tests/dummy/app/app.js index f796e79..b3b2bd6 100644 --- a/tests/dummy/app/app.js +++ b/tests/dummy/app/app.js @@ -1,11 +1,9 @@ -import Ember from 'ember'; +import Application from '@ember/application'; import Resolver from './resolver'; import loadInitializers from 'ember-load-initializers'; import config from './config/environment'; -let App; - -App = Ember.Application.extend({ +const App = Application.extend({ modulePrefix: config.modulePrefix, podModulePrefix: config.podModulePrefix, Resolver diff --git a/tests/dummy/app/controllers/post.js b/tests/dummy/app/controllers/post.js index c7a230e..e8197d1 100644 --- a/tests/dummy/app/controllers/post.js +++ b/tests/dummy/app/controllers/post.js @@ -1,9 +1,8 @@ -import Ember from 'ember'; +import { readOnly } from '@ember/object/computed'; +import Controller from '@ember/controller'; -const { computed } = Ember; - -export default Ember.Controller.extend({ - post: computed.readOnly('model'), +export default Controller.extend({ + post: readOnly('model'), actions: { publishPost(post) { diff --git a/tests/dummy/app/index.html b/tests/dummy/app/index.html index 5120bd7..61400b2 100644 --- a/tests/dummy/app/index.html +++ b/tests/dummy/app/index.html @@ -9,8 +9,8 @@ {{content-for "head"}} - - + + {{content-for "head-footer"}} diff --git a/tests/dummy/app/router.js b/tests/dummy/app/router.js index 67035dd..f14249e 100644 --- a/tests/dummy/app/router.js +++ b/tests/dummy/app/router.js @@ -1,7 +1,7 @@ -import Ember from 'ember'; +import EmberRouter from '@ember/routing/router'; import config from './config/environment'; -const Router = Ember.Router.extend({ +const Router = EmberRouter.extend({ location: config.locationType, rootURL: config.rootURL }); diff --git a/tests/dummy/app/routes/application.js b/tests/dummy/app/routes/application.js index bed71fa..6c74252 100644 --- a/tests/dummy/app/routes/application.js +++ b/tests/dummy/app/routes/application.js @@ -1,4 +1,4 @@ -import Ember from "ember"; +import Route from '@ember/routing/route'; -export default Ember.Route.extend({ +export default Route.extend({ }); diff --git a/tests/dummy/app/routes/post.js b/tests/dummy/app/routes/post.js index 67a6fdd..6f87381 100644 --- a/tests/dummy/app/routes/post.js +++ b/tests/dummy/app/routes/post.js @@ -1,21 +1,7 @@ -import Ember from 'ember'; -import RSVP from 'rsvp'; +import Route from '@ember/routing/route'; -const { get } = Ember; - -export default Ember.Route.extend({ - model(params) { - return this.store.queryRecord('post', { slug: params.slug }); - }, - - afterModel(model) { - // HACK: This prevents an issue introduced in Ember Data 2.14 (https://github.com/emberjs/data/issues/4942) - // This can safely be removed when emberjs/data#4942 has been resolved. - return RSVP.hash({ - author: get(model, 'author'), - comments: get(model, 'comments'), - reactions: get(model, 'reactions'), - relatedPosts: get(model, 'relatedPosts'), - }); - }, +export default Route.extend({ + model({ slug }) { + return this.store.queryRecord('post', { slug }); + } }); diff --git a/tests/dummy/app/routes/posts.js b/tests/dummy/app/routes/posts.js index dca84f3..364708a 100644 --- a/tests/dummy/app/routes/posts.js +++ b/tests/dummy/app/routes/posts.js @@ -1,6 +1,6 @@ -import Ember from 'ember'; +import Route from '@ember/routing/route'; -export default Ember.Route.extend({ +export default Route.extend({ model() { return this.store.findAll('post'); }, diff --git a/tests/dummy/app/routes/search.js b/tests/dummy/app/routes/search.js index 40b348a..ba64c1e 100644 --- a/tests/dummy/app/routes/search.js +++ b/tests/dummy/app/routes/search.js @@ -1,6 +1,6 @@ -import Ember from 'ember'; +import Route from '@ember/routing/route'; -export default Ember.Route.extend({ +export default Route.extend({ model({ term }) { return this.store.query('post', { filter: { term } }); }, diff --git a/tests/dummy/app/templates/application.hbs b/tests/dummy/app/templates/application.hbs index c24cd68..5230580 100644 --- a/tests/dummy/app/templates/application.hbs +++ b/tests/dummy/app/templates/application.hbs @@ -1 +1,3 @@ -{{outlet}} +
{{comment.message}}
{{/each}} diff --git a/tests/dummy/app/utils/deparam.js b/tests/dummy/app/utils/deparam.js index edd90c3..fb978ee 100644 --- a/tests/dummy/app/utils/deparam.js +++ b/tests/dummy/app/utils/deparam.js @@ -27,7 +27,7 @@ * */ var digitTest = /^\d+$/, - keyBreaker = /([^\[\]]+)|(\[\])/g, + keyBreaker = /([^[\]]+)|(\[\])/g, paramTest = /([^?#]*)(#.*)?$/, entityRegex = /%([^0-9a-f][0-9a-f]|[0-9a-f][^0-9a-f]|[^0-9a-f][^0-9a-f])/i, prep = function (str) { diff --git a/tests/dummy/config/environment.js b/tests/dummy/config/environment.js index 6a378d3..182d3fc 100644 --- a/tests/dummy/config/environment.js +++ b/tests/dummy/config/environment.js @@ -1,9 +1,9 @@ -/* eslint-env node */ +'use strict'; module.exports = function(environment) { - var ENV = { + let ENV = { modulePrefix: 'dummy', - environment: environment, + environment, rootURL: '/', locationType: 'auto', EmberENV: { @@ -40,10 +40,11 @@ module.exports = function(environment) { ENV.APP.LOG_VIEW_LOOKUPS = false; ENV.APP.rootElement = '#ember-testing'; + ENV.APP.autoboot = false; } if (environment === 'production') { - + // here you can enable a production-specific feature } return ENV; diff --git a/tests/dummy/config/targets.js b/tests/dummy/config/targets.js index 2bebfac..8ffae36 100644 --- a/tests/dummy/config/targets.js +++ b/tests/dummy/config/targets.js @@ -1,10 +1,18 @@ -/* eslint-env node */ +'use strict'; + +const browsers = [ + 'last 1 Chrome versions', + 'last 1 Firefox versions', + 'last 1 Safari versions' +]; + +const isCI = !!process.env.CI; +const isProduction = process.env.EMBER_ENV === 'production'; + +if (isCI || isProduction) { + browsers.push('ie 11'); +} module.exports = { - browsers: [ - 'ie 9', - 'last 1 Chrome versions', - 'last 1 Firefox versions', - 'last 1 Safari versions' - ] + browsers }; diff --git a/tests/dummy/mirage/factories/reaction.js b/tests/dummy/mirage/factories/reaction.js index ce2a307..86940c9 100644 --- a/tests/dummy/mirage/factories/reaction.js +++ b/tests/dummy/mirage/factories/reaction.js @@ -1,7 +1,5 @@ +import { w } from '@ember/string'; import { Factory, faker } from 'ember-cli-mirage'; -import Ember from 'ember'; - -const { String: { w } } = Ember; export default Factory.extend({ name() { diff --git a/tests/dummy/mirage/scenarios/default.js b/tests/dummy/mirage/scenarios/default.js index 0d2db8d..adb3af4 100644 --- a/tests/dummy/mirage/scenarios/default.js +++ b/tests/dummy/mirage/scenarios/default.js @@ -3,8 +3,6 @@ export default function(/* server */) { /* Seed your development database using your factories. This data will not be loaded in your tests. - - Make sure to define a factory for each model you want to create. */ // server.createList('post', 10); diff --git a/tests/dummy/mirage/serializers/application.js b/tests/dummy/mirage/serializers/application.js index 6d47a36..950746e 100644 --- a/tests/dummy/mirage/serializers/application.js +++ b/tests/dummy/mirage/serializers/application.js @@ -1,4 +1,5 @@ import { JSONAPISerializer } from 'ember-cli-mirage'; export default JSONAPISerializer.extend({ + alwaysIncludeLinkageData: true }); diff --git a/tests/dummy/public/crossdomain.xml b/tests/dummy/public/crossdomain.xml deleted file mode 100644 index 0c16a7a..0000000 --- a/tests/dummy/public/crossdomain.xml +++ /dev/null @@ -1,15 +0,0 @@ - - -