Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
adca042
decaffeinate: Rename index.coffee from .coffee to .js
chrisbreiding Feb 4, 2020
553f4c8
decaffeinate: Convert index.coffee to JS
chrisbreiding Feb 4, 2020
c61c164
decaffeinate: Run post-processing cleanups on index.coffee
chrisbreiding Feb 4, 2020
2f86565
refactor decaffeinated plugins/index.js
chrisbreiding Feb 4, 2020
fd34c3e
decaffeinate: Rename 3_plugins_spec.coffee from .coffee to .js
chrisbreiding Feb 4, 2020
cd741b3
decaffeinate: Convert 3_plugins_spec.coffee to JS
chrisbreiding Feb 4, 2020
cfdd811
decaffeinate: Run post-processing cleanups on 3_plugins_spec.coffee
chrisbreiding Feb 4, 2020
51f95b2
fix wrongly removed return
chrisbreiding Feb 4, 2020
3c40503
refactor e2e plugins spec, update snapshot
chrisbreiding Feb 4, 2020
a6e187b
pass env argument to plugins file
chrisbreiding Feb 4, 2020
acf8a4d
decaffeinate: Rename index_spec.coffee from .coffee to .js
chrisbreiding Feb 4, 2020
4f15023
decaffeinate: Convert index_spec.coffee to JS
chrisbreiding Feb 4, 2020
ca90189
decaffeinate: Run post-processing cleanups on index_spec.coffee
chrisbreiding Feb 4, 2020
7b7af51
update plugins tests
chrisbreiding Feb 4, 2020
ef5d95d
update scaffold snapshot
chrisbreiding Feb 4, 2020
083bd5e
Merge branch 'develop' into issue-5941-plugins-file-options
chrisbreiding Feb 5, 2020
a3675a3
Merge branch 'develop' into issue-5941-plugins-file-options
chrisbreiding Feb 21, 2020
90a1fe8
Merge branch 'issue-5941-plugins-file-options' of github.com:cypress-…
chrisbreiding Feb 21, 2020
709a970
add back server test script and document running individual tests
chrisbreiding Feb 21, 2020
04045d2
add projectRoot and configFile directly to config
chrisbreiding Feb 21, 2020
0a5799a
normalize browsers in snapshot
chrisbreiding Feb 21, 2020
81e807d
add types for configFile and projectRoot
chrisbreiding Feb 21, 2020
a2ad4c7
Merge branch 'develop' into issue-5941-plugins-file-options
chrisbreiding Feb 21, 2020
db25c38
Merge branch 'develop' into issue-5941-plugins-file-options
chrisbreiding Feb 24, 2020
829bc06
fix linting issues
chrisbreiding Feb 24, 2020
0f2abe4
return return
chrisbreiding Feb 25, 2020
5fb39df
Merge
chrisbreiding Feb 25, 2020
940aa2a
Merge branch 'develop' into issue-5941-plugins-file-options
chrisbreiding Feb 25, 2020
e961eff
remove file
chrisbreiding Feb 25, 2020
aefdb36
remove unnecessary returns
chrisbreiding Feb 26, 2020
850c1f6
Merge branch 'develop' into issue-5941-plugins-file-options
chrisbreiding Feb 28, 2020
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
13 changes: 12 additions & 1 deletion cli/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ declare namespace Cypress {
type RequestBody = string | object
type ViewportOrientation = "portrait" | "landscape"
type PrevSubject = "optional" | "element" | "document" | "window"
type PluginConfig = (on: PluginEvents, config: ConfigOptions) => void | Partial<ConfigOptions> | Promise<Partial<ConfigOptions>>
type PluginConfig = (on: PluginEvents, config: PluginConfigOptions) => void | Partial<ConfigOptions> | Promise<Partial<ConfigOptions>>

interface CommandOptions {
prevSubject: boolean | PrevSubject | PrevSubject[]
Expand Down Expand Up @@ -2282,6 +2282,17 @@ declare namespace Cypress {
firefoxGcInterval: Nullable<number | { runMode: Nullable<number>, openMode: Nullable<number> }>
}

interface PluginConfigOptions extends ConfigOptions {
/**
* Absolute path to the config file (default: <projectRoot>/cypress.json) or false
*/
configFile: string | false
/**
* Absolute path to the root of the project
*/
projectRoot: string
}

interface DebugOptions {
verbose: boolean
}
Expand Down
4 changes: 3 additions & 1 deletion cli/types/tests/plugins-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ const pluginConfig: Cypress.PluginConfig = (on, config) => {}

// allows synchronous returns
const pluginConfig2: Cypress.PluginConfig = (on, config) => {
config // $ExpectType ConfigOptions
config // $ExpectType PluginConfigOptions
config.baseUrl // $ExpectType: string
config.configFile // $ExpectType: string | false
config.projectRoot // $ExpectType: string

on('before:browser:launch', (browser, options) => {
browser.displayName // $ExpectType string
Expand Down
404 changes: 0 additions & 404 deletions packages/server/__snapshots__/3_plugins_spec.coffee.js

This file was deleted.

18 changes: 9 additions & 9 deletions packages/server/__snapshots__/3_plugins_spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
exports['e2e plugins passes 1'] = `
exports['e2e plugins passes with working preprocessor 1'] = `

====================================================================================================

Expand Down Expand Up @@ -58,7 +58,7 @@ exports['e2e plugins passes 1'] = `

`

exports['e2e plugins fails 1'] = `
exports['e2e plugins fails with async error 1'] = `

====================================================================================================

Expand Down Expand Up @@ -175,13 +175,6 @@ exports['e2e plugins can modify config from plugins 1'] = `
✔ All specs passed! XX:XX 2 2 - - -


`

exports['e2e plugins catches invalid viewportWidth returned from plugins 1'] = `
An invalid configuration value returned from the plugins file: \`cypress/plugins/index.coffee\`

Expected \`viewportWidth\` to be a number. Instead the value was: \`"foo"\`

`

exports['e2e plugins catches invalid browsers list returned from plugins 1'] = `
Expand Down Expand Up @@ -402,3 +395,10 @@ exports['e2e plugins calls after:screenshot for cy.screenshot() and failure scre


`

exports['e2e plugins catches invalid viewportWidth returned from plugins 1'] = `
An invalid configuration value returned from the plugins file: \`cypress/plugins/index.coffee\`

Expected \`viewportWidth\` to be a number. Instead the value was: \`"foo"\`

`
17 changes: 10 additions & 7 deletions packages/server/lib/plugins/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,16 @@ const init = (config, options) => {
handler(ipc)
}

_.extend(config, {
projectRoot: options.projectRoot,
configFile: options.configFile,
})

ipc.send('load', config)

ipc.on('loaded', (newCfg, registrations) => {
_.omit(config, 'projectRoot', 'configFile')

_.each(registrations, (registration) => {
debug('register plugins process event', registration.event, 'with id', registration.eventId)

Expand Down Expand Up @@ -105,9 +112,7 @@ const init = (config, options) => {

const handleError = (err) => {
debug('plugins process error:', err.stack)
if (!pluginsProcess) {
return // prevent repeating this in case of multiple errors
}
if (!pluginsProcess) return // prevent repeating this in case of multiple errors

killPluginsProcess()
err = errors.get('PLUGINS_ERROR', err.annotated || err.stack || err.message)
Expand All @@ -116,11 +121,9 @@ const init = (config, options) => {
return options.onError(err)
}

const handleWarning = function (warningErr) {
const handleWarning = (warningErr) => {
debug('plugins process warning:', warningErr.stack)
if (!pluginsProcess) {
return // prevent repeating this in case of multiple warnings
}
if (!pluginsProcess) return // prevent repeating this in case of multiple warnings

return options.onWarning(warningErr)
}
Expand Down
2 changes: 2 additions & 0 deletions packages/server/lib/project.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,8 @@ class Project extends EE {
cfg = config.whitelist(cfg)

return plugins.init(cfg, {
projectRoot: this.projectRoot,
configFile: settings.pathToConfigFile(this.projectRoot, options),
onError (err) {
debug('got plugins error', err.stack)

Expand Down
47 changes: 44 additions & 3 deletions packages/server/test/e2e/3_plugins_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const path = require('path')
const e2e = require('../support/helpers/e2e')
const Fixtures = require('../support/helpers/fixtures')

const e2eProject = Fixtures.projectPath('e2e')
const pluginExtension = Fixtures.projectPath('plugin-extension')
const pluginConfig = Fixtures.projectPath('plugin-config')
const pluginFilterBrowsers = Fixtures.projectPath('plugin-filter-browsers')
Expand All @@ -14,10 +15,10 @@ const pluginReturnsBadConfig = Fixtures.projectPath('plugin-returns-bad-config')
const pluginReturnsEmptyBrowsersList = Fixtures.projectPath('plugin-returns-empty-browsers-list')
const pluginReturnsInvalidBrowser = Fixtures.projectPath('plugin-returns-invalid-browser')

describe('e2e plugins', () => {
describe('e2e plugins', function () {
e2e.setup()

it('passes', function () {
it('passes with working preprocessor', function () {
return e2e.exec(this, {
spec: 'app_spec.coffee',
project: workingPreprocessor,
Expand All @@ -26,7 +27,7 @@ describe('e2e plugins', () => {
})
})

it('fails', function () {
it('fails with async error', function () {
return e2e.exec(this, {
spec: 'app_spec.coffee',
project: pluginsAsyncError,
Expand Down Expand Up @@ -121,4 +122,44 @@ describe('e2e plugins', () => {
expectedExitCode: 1,
})
})

describe('projectRoot and configFile', function () {
it('passes projectRoot and default configFile to plugins function', function () {
return e2e.exec(this, {
spec: 'plugins_config_extras_spec.js',
config: {
env: {
projectRoot: e2eProject,
configFile: path.join(e2eProject, 'cypress.json'),
},
},
})
})

it('passes custom configFile to plugins function', function () {
return e2e.exec(this, {
spec: 'plugins_config_extras_spec.js',
configFile: 'cypress-alt.json',
config: {
env: {
projectRoot: e2eProject,
configFile: path.join(e2eProject, 'cypress-alt.json'),
},
},
})
})

it('passes false configFile to plugins function', function () {
return e2e.exec(this, {
spec: 'plugins_config_extras_spec.js',
configFile: 'false',
config: {
env: {
projectRoot: e2eProject,
configFile: false,
},
},
})
})
})
})
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
describe('plugins config extras', () => {
it('has correct projectRoot', () => {
cy.task('get:config:value', 'projectRoot')
.should('not.be.undefined')
.and('equal', Cypress.env('projectRoot'))
})

it('has correct configFile', () => {
cy.task('get:config:value', 'configFile')
.should('not.be.undefined')
.and('equal', Cypress.env('configFile'))
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -151,5 +151,9 @@ module.exports = (on, config) => {
'get:browser:args' () {
return browserArgs
},

'get:config:value' (key) {
return config[key]
},
})
}
4 changes: 4 additions & 0 deletions packages/server/test/support/helpers/e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,10 @@ const e2e = {
args.push(`--tag=${options.tag}`)
}

if (options.configFile) {
args.push(`--config-file=${options.configFile}`)
}

return args
},

Expand Down
5 changes: 4 additions & 1 deletion packages/server/test/unit/browsers/browsers_spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ browsers = require("#{root}../lib/browsers")
utils = require("#{root}../lib/browsers/utils")
snapshot = require('snap-shot-it')

normalizeBrowsers = (message) ->
message.replace(/(found are: ).*/, "$1chrome, firefox, electron")

describe "lib/browsers/index", ->
context ".getBrowserInstance", ->
it "returns instance", ->
Expand Down Expand Up @@ -40,7 +43,7 @@ describe "lib/browsers/index", ->
expect(browsers.ensureAndGetByNameOrPath("browserNotGonnaBeFound"))
.to.be.rejectedWith({ type: 'BROWSER_NOT_FOUND_BY_NAME' })
.then (err) ->
snapshot(err.message)
snapshot(normalizeBrowsers(err.message))

it "throws a special error when canary is passed", ->
sinon.stub(utils, "getBrowsers").resolves([
Expand Down
Loading