forked from cypress-io/cypress
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtask_spec.js
More file actions
70 lines (55 loc) · 3.45 KB
/
task_spec.js
File metadata and controls
70 lines (55 loc) · 3.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
require('../spec_helper')
const Promise = require('bluebird')
const plugins = require(`../../lib/plugins`)
const task = require(`../../lib/task`)
describe('lib/task', () => {
beforeEach(function () {
this.configFilePath = 'cypress.config.js'
sinon.stub(plugins, 'execute').resolves('result')
return sinon.stub(plugins, 'has').returns(true)
})
it('executes the \'task\' plugin', function () {
return task.run(this.configFilePath, { task: 'some:task', arg: 'some:arg', timeout: 1000 }).then(() => {
expect(plugins.execute).to.be.calledWith('task', 'some:task', 'some:arg')
})
})
it('resolves the result of the \'task\' plugin', function () {
return task.run(this.configFilePath, { task: 'some:task', arg: 'some:arg', timeout: 1000 }).then((result) => {
expect(result).to.equal('result')
})
})
it('throws if \'task\' event is not registered', function () {
plugins.has.returns(false)
return task.run(this.configFilePath, { timeout: 1000 }).catch((err) => {
expect(err.message).to.equal(`The 'task' event has not been registered in the setupNodeEvents method. You must register it before using cy.task()\n\nFix this in your setupNodeEvents method here:\n${this.configFilePath}`)
})
})
it('throws if \'task\' event resolves __cypress_unhandled__', function () {
plugins.execute.withArgs('task').resolves('__cypress_unhandled__')
plugins.execute.withArgs('_get:task:keys').resolves(['foo', 'bar'])
return task.run(this.configFilePath, { task: 'some:task', arg: 'some:arg', timeout: 1000 }).catch((err) => {
expect(err.message).to.equal(`The task 'some:task' was not handled in the setupNodeEvents method. The following tasks are registered: foo, bar\n\nFix this in your setupNodeEvents method here:\n${this.configFilePath}`)
})
})
it('throws if \'task\' event resolves undefined', function () {
plugins.execute.withArgs('task').resolves(undefined)
plugins.execute.withArgs('_get:task:body').resolves('function () {}')
return task.run(this.configFilePath, { task: 'some:task', arg: 'some:arg', timeout: 1000 }).catch((err) => {
expect(err.message).to.equal(`The task 'some:task' returned undefined. You must return a value, null, or a promise that resolves to a value or null to indicate that the task was handled.\n\nThe task handler was:\n\nfunction () {}\n\nFix this in your setupNodeEvents method here:\n${this.configFilePath}`)
})
})
it('throws if \'task\' event resolves undefined - without task body', function () {
plugins.execute.withArgs('task').resolves(undefined)
plugins.execute.withArgs('_get:task:body').resolves('')
return task.run(this.configFilePath, { task: 'some:task', arg: 'some:arg', timeout: 1000 }).catch((err) => {
expect(err.message).to.equal(`The task 'some:task' returned undefined. You must return a value, null, or a promise that resolves to a value or null to indicate that the task was handled.\n\nFix this in your setupNodeEvents method here:\n${this.configFilePath}`)
})
})
it('throws if it times out', function () {
plugins.execute.withArgs('task').resolves(Promise.delay(250))
plugins.execute.withArgs('_get:task:body').resolves('function () {}')
return task.run(this.configFilePath, { task: 'some:task', arg: 'some:arg', timeout: 10 }).catch((err) => {
expect(err.message).to.equal(`The task handler was:\n\nfunction () {}\n\nFix this in your setupNodeEvents method here:\n${this.configFilePath}`)
})
})
})