-
-
Notifications
You must be signed in to change notification settings - Fork 51
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
Support live reload and add optional debug log #158
Conversation
node-tests/e2e/test-support-test.js
Outdated
afterEach(async function() { | ||
await removeConfig(testProject); | ||
}); |
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.
Global afterEach
caused issues because it was running after every test even if part of a describe
hook. Some describe
blocks are running multiple tests against the same running development server. After fixing live reload support this showed strange timing issues. Moved all tests into describe hooks and avoided global afterEach
to have a more fine granular control.
node-tests/e2e/test-support-test.js
Outdated
describe('causes tests to fail on CSP violations', async function() { | ||
afterEach(async function() { | ||
await removeConfig(testProject); | ||
}); |
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.
Global afterEach
caused issues because it was running after every test even if part of a describe
hook. Some describe
blocks are running multiple tests against the same running development server. After fixing live reload support this showed strange timing issues. Moved all tests into describe hooks and avoided global afterEach
to have a more fine granular control.
node-tests/e2e/test-support-test.js
Outdated
it('does not cause tests failures if addon is disabled', async function() { | ||
await setConfig(testProject, { | ||
enabled: false, | ||
}); | ||
let { exitCode } = await testProject.runEmberCommand('test'); | ||
|
||
expect(exitCode).to.equal(0); | ||
}); | ||
|
||
it('does not cause tests failures if `failTests` config option is `false`', async function() { | ||
await setConfig(testProject, { | ||
failTests: false, | ||
}); | ||
|
||
let { exitCode } = await testProject.runEmberCommand('test'); | ||
|
||
expect(exitCode).to.equal(0); | ||
}); | ||
|
||
// One common scenario is when running the server in production mode locally, i.e. | ||
// you are doing the production build on your local machine, connecting to your actual production server, | ||
// for example via `ember serve -prod`. In these cases we don't want this addon to break. | ||
it('does not break development server for builds not including tests', async function() { | ||
// TODO: not supported yet | ||
await testProject.startEmberServer({ | ||
environment: 'prodocution', | ||
port: '49741', | ||
}); | ||
|
||
let response = await request({ | ||
url: 'http://localhost:49741/', | ||
headers: { | ||
'Accept': 'text/html' | ||
} | ||
}); | ||
let responseForTests = await request({ | ||
url: 'http://localhost:49741/tests', | ||
headers: { | ||
'Accept': 'text/html' | ||
} | ||
}); | ||
|
||
expect(response.statusCode).to.equal(200); | ||
expect(responseForTests.statusCode).to.equal(200); | ||
|
||
await testProject.stopEmberServer(); | ||
}); |
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.
These tests are just moved from another position within the file. Beside that they are untouched if I recall correctly.
const { project } = this; | ||
const { ui } = project; | ||
const ownConfig = readConfig(project, environment); | ||
const runConfig = this._runConfig; |
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.
Haven't researched if the run-time configuration is available through some public API on the project
or app
. I'm not a big fan of storing it in config
hook and using it later. But I didn't wanted to touch to many parts at the same time.
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.
Looks good to me!
e559d01
to
d529a16
Compare
Ember CLI Content Security Policy had cached its configuration. This broke live reload because the cache was not invalidated when the addon's configuration file changed. This was reported in #146. Beside causing this bug the caching also added a lot of complexity.
This pull request removes the caching all together. Instead the configuration is calculated whenever it's needed. This has a negative impact on performance. Especially because configuration file is read multiple times - even for the same build. But I don't think the performance impact is noticeable by end-user because the file is still read less than 10 times, it's very small and filesystem caching should speed up subsequent reads.
It also avoid adding
report-uri
to a policy, which is delivered via meta tag. This addresses #148 at least partly.Additionally it introduces a debug output using debug NPM package. User can opt-in to debug output by setting
DEBUG
environment variable toember-cli-content-security-policy
, e.g.DEBUG=ember-cli-content-security-policy ember build
.The debug package is used in ember-auto-import, embroider and ember-data. It seems to be a well established tool in Ember ecosystem.
Closes #146