|
1
|
|
|
import { expect } from 'chai'; |
|
2
|
|
|
import intercept from 'intercept-stdout'; |
|
3
|
|
|
import { IO, resolveValue, triggerWarnings } from '../src/input'; |
|
4
|
|
|
import { String as Text } from '../src/types'; |
|
5
|
|
|
import { compileES6 } from '../src/compiler'; |
|
6
|
|
|
|
|
7
|
|
|
describe('input.js', () => { |
|
8
|
|
|
describe('Value parsing', () => { |
|
9
|
|
|
it('should get a simple string', () => { |
|
10
|
|
|
const value = resolveValue('test', Text, null, true); |
|
11
|
|
|
expect(value).to.equals('test'); |
|
12
|
|
|
}); |
|
13
|
|
|
|
|
14
|
|
|
it('should return null for a required string', () => { |
|
15
|
|
|
const value = resolveValue('', Text, null, true); |
|
16
|
|
|
expect(value).to.be.null; |
|
17
|
|
|
}); |
|
18
|
|
|
|
|
19
|
|
|
it('should accept the default value of a string', () => { |
|
20
|
|
|
const value = resolveValue('', Text, 'alaska', false); |
|
21
|
|
|
expect(value).to.equals('alaska'); |
|
22
|
|
|
}); |
|
23
|
|
|
}); |
|
24
|
|
|
|
|
25
|
|
|
describe('Warnings', () => { |
|
26
|
|
|
it('should trigger a warning when has named parameter language', () => { |
|
27
|
|
|
let result = ''; |
|
28
|
|
|
const stopReading = intercept(text => result += text); |
|
29
|
|
|
const io = IO(); |
|
30
|
|
|
triggerWarnings(io, { language: {} }) |
|
31
|
|
|
.then(() => { |
|
32
|
|
|
stopReading(); |
|
33
|
|
|
expect(result).to.match(/Warning: don't use context.params.language/); |
|
34
|
|
|
}); |
|
35
|
|
|
}); |
|
36
|
|
|
}); |
|
37
|
|
|
}); |