-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsendKeys.test.js
56 lines (49 loc) · 1.64 KB
/
sendKeys.test.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
'use strict'
const {
spawnPowershellScript,
spawnPowershellScriptSync,
scriptFactory,
argumentChecker
} = require('./sendKeys.factory.win')
describe('happy path', () => {
it('spawns a powershell script', () => {
const proc = spawnPowershellScript('[System.Console]::WriteLine("foobar")')
return expect(proc).resolves.toBeUndefined()
})
it('spawns a powershell script and fails', () => {
const script = '[System.Console]::foo("bar")' // doesn't exists
const proc = spawnPowershellScript(script)
return expect(proc).rejects.toContain(script)
})
it('spawns a powershell script SYNC', () => {
const res = spawnPowershellScriptSync(
'[System.Console]::WriteLine("foobar")'
)
return expect(res).toBeUndefined()
})
it('spawns a powershell script and fails SYNC', () => {
const script = '[System.Console]::foo("bar")' // doesn't exists
expect(() => spawnPowershellScriptSync(script)).toThrow()
})
const csSource1 = `
public class StartUp {
public static void Invoke(string str) {
System.Console.WriteLine(str);
}
}`
it('makes a script and spawns and succeed', () => {
const script = scriptFactory(csSource1)
const command = script('foo')
const proc = spawnPowershellScript(command)
return expect(proc).resolves.toBeUndefined()
})
it('should fail if the argument is not a string', () => {
expect(() => argumentChecker('keys', 'string')).not.toThrow()
expect(() => argumentChecker(10, 'string')).toThrowError(
/Argument must be/i
)
expect(() => argumentChecker({ foo: 'bar' }, 'string')).toThrowError(
/Argument must be/i
)
})
})