From 46c63b350c01b6e75c8d0be4bb065b7d5a9b6b0a Mon Sep 17 00:00:00 2001 From: Marco Otte-Witte Date: Wed, 4 Apr 2018 18:41:32 +0200 Subject: [PATCH 1/2] test in Firefox on CI --- .travis.yml | 1 + testem.js | 9 ++++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 84af0d7d..958744c0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,6 +7,7 @@ dist: trusty addons: chrome: stable + firefox: latest cache: yarn: true diff --git a/testem.js b/testem.js index 028b4f35..98f8c2a4 100644 --- a/testem.js +++ b/testem.js @@ -5,12 +5,19 @@ module.exports = { test_page: 'tests/index.html?hidepassed', disable_watching: true, launch_in_ci: [ - 'Chrome' + 'Chrome', + 'Firefox' ], launch_in_dev: [ 'Chrome' ], browser_args: { + Firefox: { + mode: 'ci', + args: [ + '-headless' + ] + }, Chrome: { mode: 'ci', args: [ From e58d25ac745419ea48fb1ab78d8d3acfe7e9c2ed Mon Sep 17 00:00:00 2001 From: Marco Otte-Witte Date: Fri, 8 Mar 2019 10:29:12 +0100 Subject: [PATCH 2/2] fix tests in Firefox --- addon/services/cookies.js | 11 ++++++++++- testem.js | 3 ++- tests/unit/services/cookies-test.js | 10 ++++++++-- 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/addon/services/cookies.js b/addon/services/cookies.js index 7cc5ecad..499e8e5e 100644 --- a/addon/services/cookies.js +++ b/addon/services/cookies.js @@ -84,6 +84,8 @@ export default Service.extend({ this._writeFastBootCookie(name, value, options); } else { assert('Cookies cannot be set to be HTTP-only from a browser!', !options.httpOnly); + + options.path = options.path || this._normalizedDefaultPath(); this._writeDocumentCookie(name, value, options); } }, @@ -93,6 +95,7 @@ export default Service.extend({ assert('Expires, Max-Age, and raw options cannot be set when clearing cookies', isEmpty(options.expires) && isEmpty(options.maxAge) && isEmpty(options.raw)); options.expires = new Date('1970-01-01'); + options.path = options.path || this._normalizedDefaultPath(); this.write(name, null, options); }, @@ -252,6 +255,12 @@ export default Service.extend({ } return _byteCount < MAX_COOKIE_BYTE_LENGTH; - } + }, + _normalizedDefaultPath() { + if (!this.get('_isFastBoot')) { + let pathname = window.location.pathname; + return pathname.substring(0, pathname.lastIndexOf('/')); + } + } }); diff --git a/testem.js b/testem.js index 98f8c2a4..44ea4e59 100644 --- a/testem.js +++ b/testem.js @@ -9,7 +9,8 @@ module.exports = { 'Firefox' ], launch_in_dev: [ - 'Chrome' + 'Chrome', + 'Firefox' ], browser_args: { Firefox: { diff --git a/tests/unit/services/cookies-test.js b/tests/unit/services/cookies-test.js index eff4a1e2..38c4dad9 100644 --- a/tests/unit/services/cookies-test.js +++ b/tests/unit/services/cookies-test.js @@ -101,8 +101,11 @@ describe('CookiesService', function() { }); afterEach(function() { + let pathname = window.location.pathname; + pathname = pathname.substring(0, pathname.lastIndexOf('/')); document.cookie = `${COOKIE_NAME}=whatever; expires=${new Date(0).toUTCString()}`; - document.cookie = `${COOKIE_NAME}=whatever; path=${window.location.pathname}; expires=${new Date(0).toUTCString()}`; + document.cookie = `${COOKIE_NAME}=whatever; path=${pathname}; expires=${new Date(0).toUTCString()}`; + document.cookie = `${COOKIE_NAME}=whatever; path=${pathname}/; expires=${new Date(0).toUTCString()}`; }); describe('reading a cookie', function() { @@ -152,6 +155,7 @@ describe('CookiesService', function() { it('returns the cookie value for a cookie that was written for the same path', function() { let path = window.location.pathname; + path = path.substring(0, path.lastIndexOf('/')); let value = randomString(); this.subject().write(COOKIE_NAME, value, { path }); @@ -328,7 +332,9 @@ describe('CookiesService', function() { it('clears the cookie', function() { let value = randomString(); - document.cookie = `${COOKIE_NAME}=${value};`; + let pathname = window.location.pathname; + let path = pathname.substring(0, pathname.lastIndexOf('/')); + document.cookie = `${COOKIE_NAME}=${value}; path=${path};`; expect(this.subject().read(COOKIE_NAME)).to.eq(value);