Skip to content
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

feat: support asynchronous config.set() call in karma.conf.js #3660

Merged
Merged
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
62892fa
feat: initial promise support for `parseConfig` and `Server`
npetruzzelli Feb 28, 2021
39b9f80
feat: add promise support to `parseConfig`'s fail function
npetruzzelli Feb 28, 2021
c6c4314
feat: add async config support to `cli`, `runner`, and `stopper`
npetruzzelli Mar 2, 2021
35c992e
chore: rename `cmdSupportsConfigPromise` to `cmdNeedsConfig`
npetruzzelli Mar 5, 2021
1a8ce58
fix: catch config errors and exit
npetruzzelli Mar 5, 2021
088aa79
chore: remove throwErrors implication from promiseConfig option
npetruzzelli Mar 5, 2021
5d92865
fix: add warning for deprecated use of CLI options
npetruzzelli Mar 5, 2021
8a52b2b
fix: treat rejections the same as exceptions
npetruzzelli Mar 11, 2021
c4fd16e
chore: setup logger early when promises are used
npetruzzelli Mar 11, 2021
e4f4887
chore: remove obsolete `console.error`
npetruzzelli Mar 11, 2021
a43554b
chore: guard `logger.setupFromConfig` calls
npetruzzelli Mar 11, 2021
8490ed6
chore: update documentation for parseConfig
npetruzzelli Mar 11, 2021
63dc58f
fix: remove excess config assignment
npetruzzelli Mar 12, 2021
4c09e03
chore: document only new behavior with promises
npetruzzelli Mar 12, 2021
65e583d
chore: remove reference to example that is no longer accurate
npetruzzelli Mar 12, 2021
765cd0e
chore: update Server constructor docs
npetruzzelli Mar 12, 2021
ae7dbf7
chore: update runner and stopper docs
npetruzzelli Mar 12, 2021
91bf78a
chore: replace redundant formatting in headers
npetruzzelli Mar 12, 2021
e63c3e8
fix: replace header text that was accidentally removed
npetruzzelli Mar 12, 2021
4d8e7ea
chore: remove comment per code review
npetruzzelli Mar 15, 2021
3038717
chore: make async CLI branches testable
npetruzzelli Mar 15, 2021
8dd8d2c
chore: test CLI `run()` commands
npetruzzelli Mar 15, 2021
5a3ad45
chore: test that server logs deprecation warning
npetruzzelli Mar 17, 2021
212e791
chore: initial tests for async parseConfig
npetruzzelli Mar 17, 2021
a547795
fix: isThenable criteria should be consistent with aPlus spec
npetruzzelli Mar 17, 2021
b5ddd20
chore: minor IDE support via JSDoc block
npetruzzelli Mar 17, 2021
027e4b0
chore: simplify async test wrapper
npetruzzelli Mar 22, 2021
e4b1918
chore: reduce async noise in `run`
npetruzzelli Mar 22, 2021
d44b5df
chore: check `instanceof` for Promise object in tests
npetruzzelli Mar 22, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
chore: make async CLI branches testable
  • Loading branch information
npetruzzelli committed Mar 15, 2021
commit 3038717aea6266f6bdd1c7ffd949d49944ab5b13
40 changes: 28 additions & 12 deletions lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -282,28 +282,33 @@ exports.run = () => {
const cliOptions = exports.process()
const cmd = cliOptions.cmd // prevent config from changing the command
const cmdNeedsConfig = cmd === 'start' || cmd === 'run' || cmd === 'stop'
let runPromise
if (cmdNeedsConfig) {
cfg.parseConfig(
runPromise = cfg.parseConfig(
devoto13 marked this conversation as resolved.
Show resolved Hide resolved
cliOptions.configFile,
cliOptions,
{
promiseConfig: true,
throwErrors: true
}
).then(function onKarmaConfigFulfilled (config) {
let fulfillmentValue
switch (cmd) {
case 'start':
new Server(config).start()
case 'start': {
const server = new Server(config)
fulfillmentValue = server.start().then(() => server)
break
}
case 'run':
require('./runner')
fulfillmentValue = require('./runner')
.run(config)
.on('progress', printRunnerProgress)
break
case 'stop':
require('./stopper').stop(config)
fulfillmentValue = require('./stopper').stop(config)
break
}
return fulfillmentValue
}, function onKarmaConfigRejected (/* ignoredReason */) {
// The reject reason isn't used to log a message since parseConfig already
// calls a configured logger method with an almost identical message.
Expand All @@ -313,15 +318,26 @@ exports.run = () => {
process.exit(1)
})
} else {
switch (cmd) {
case 'init':
require('./init').init(cliOptions)
break
case 'completion':
require('./completion').completion(cliOptions)
break
try {
let fulfillmentValue
switch (cmd) {
case 'init':
fulfillmentValue = require('./init').init(cliOptions)
break
case 'completion':
fulfillmentValue = require('./completion').completion(cliOptions)
break
}
runPromise = Promise.resolve(fulfillmentValue)
} catch (ex) {
runPromise = Promise.reject(ex)
}
}

// Always return a promise for ease of testing. We want to know when it is
// safe to start making assertions. Without the promise, it would be difficult
// to test the asynchronous branches.
return runPromise
}

// just for testing
Expand Down