-
Notifications
You must be signed in to change notification settings - Fork 146
/
Copy pathExternalApi.spec.ts
62 lines (57 loc) · 1.71 KB
/
ExternalApi.spec.ts
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
import { expect } from 'chai'
import ExternalApi from '../../../../src/main/translate/ExternalApi'
describe('ExternalApi', () => {
before(() => {
(global as any).__baseDir = __dirname
})
it('gets translation from external JS file', (done) => {
const qq = new ExternalApi({
enable: true,
external: true,
jsFile: '../../temp/qqApi.js',
name: 'qq'
})
qq.translate(
'悠真くんを攻略すれば210円か。なるほどなぁ…',
(translation) => {
try {
expect(translation).to.equal('攻略悠真的话是210日元啊。原来如此啊……')
} catch (e) {
return done(e)
}
done()
}
)
}).timeout(5000)
it('keeps session when request multiple times', (done) => {
const qq = new ExternalApi({
enable: true,
external: true,
jsFile: '../../temp/qqApi.js',
name: 'qq'
})
qq.translate(
'悠真くんを攻略すれば210円か。なるほどなぁ…',
(translation1) => {
try {
expect(translation1).to.equal('攻略悠真的话是210日元啊。原来如此啊……')
qq.translate(
'はいっ、今日は柚子の入浴剤が入ってました。お湯も少し白くて温泉みたいでしたよ?',
(translation2) => {
try {
expect(translation2).to.equal(
'是的,今天放了柚子的沐浴剂。热水也有点白,就像温泉一样呢?'
)
done()
} catch (e) {
return done(e)
}
}
)
} catch (e) {
return done(e)
}
}
)
}).timeout(5000)
})