-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathatom-phpunit-spec.js
85 lines (56 loc) · 2.58 KB
/
atom-phpunit-spec.js
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
'use babel';
import AtomPhpunit from '../lib/atom-phpunit';
const fixture = require.resolve('./fixtures/FixtureTest.php');
describe('atom-phpunit', () => {
// activate the package and open the fixture file
beforeEach(() => {
waitsForPromise(() => atom.workspace.open(fixture, {initialLine: 7}))
runs(() => {
atom.packages.activatePackage('atom-phpunit')
})
})
it('can get the current file path', () => {
expect(AtomPhpunit.getFilepath()).toBe(fixture);
})
it('can get the current function name', () => {
expect(AtomPhpunit.getFunctionName()).toBe('test_method');
})
describe('when executing commands', () => {
// helper function to wait for async commands to run, then run a callback of expectations
const runCommandThen = (expectations) => {
let done = false;
runs(() => AtomPhpunit.execute().then(exec => exec.on('exit', () => done = true )))
waitsFor(() => done, "The command should be complete", 250 )
runs(expectations)
}
// spoof the command to just print a string
beforeEach(() => {
atom.config.set('atom-phpunit.useVendor',false)
atom.config.set('atom-phpunit.phpunitPath','php -r "echo \\\"the command has run\\\";"')
})
afterEach(() => {
atom.config.unset('atom-phpunit.useVendor')
atom.config.unset('atom-phpunit.phpunitPath')
});
it('succeeds and updates the output panel', () => {
runCommandThen(() => expect(AtomPhpunit.errorView.getElement().innerText).toMatch(/the command has run/))
})
describe('when notifications are being used', () => {
it('adds a notification', () => {
runCommandThen(() => {
expect(atom.notifications.getNotifications().length).not.toBe(0)
expect(AtomPhpunit.errorView.element.classList.contains('error')).toBe(false)
expect(AtomPhpunit.outputPanel.isVisible()).toBe(false)
})
})
})
describe('when notifications are NOT being used', () => {
beforeEach(() => atom.config.set('atom-phpunit.successAsNotifications',false))
afterEach(() => atom.config.unset('atom-phpunit.successAsNotifications'))
it('displays the output panel', () => {
expect(AtomPhpunit.outputPanel.isVisible()).toBe(false)
runCommandThen(() => expect(AtomPhpunit.outputPanel.isVisible()).toBe(true))
})
})
})
})