1
|
|
|
import path from 'path'; |
2
|
|
|
import { assert } from 'chai'; |
3
|
|
|
import fs from 'fs-extra'; |
4
|
|
|
import Packer from '../entry'; |
5
|
|
|
import Test from '../Test'; |
6
|
|
|
import { tmpFolder } from '../constants'; |
7
|
|
|
|
8
|
|
|
const factory = new Test(); |
9
|
|
|
|
10
|
|
|
suite('Packer: self run'); |
11
|
|
|
|
12
|
|
|
before(async function () { |
13
|
|
|
await factory.setTmpFolder(); |
14
|
|
|
}); |
15
|
|
|
|
16
|
|
|
test('packModule', async function () { |
17
|
|
|
const dir = path.join(tmpFolder, 'packModule'); |
18
|
|
|
const packer = new Packer({ dir }); |
19
|
|
|
|
20
|
|
|
await packer.ready; |
21
|
|
|
await packer.packModule(); |
22
|
|
|
|
23
|
|
|
const tarPath = packer.tarPath; |
24
|
|
|
|
25
|
|
|
assert.notInclude(path.relative(dir, tarPath), '..', 'tarPath should be inside dir'); |
26
|
|
|
assert.isTrue(await fs.exists(tarPath), 'tarFile exists'); |
27
|
|
|
}); |
28
|
|
|
|
29
|
|
|
test('packTests', async function () { |
30
|
|
|
const dir = path.join(tmpFolder, 'packTests'); |
31
|
|
|
const packer = new Packer({ dir }); |
32
|
|
|
|
33
|
|
|
await packer.ready; |
34
|
|
|
await packer.packModule(); |
35
|
|
|
await packer.packTests(); |
36
|
|
|
|
37
|
|
|
assert.isTrue(await fs.exists(path.join(dir, 'tests.js')), 'tests.js exists'); |
38
|
|
|
}); |
39
|
|
|
|
40
|
|
|
test('prepare', async function () { |
41
|
|
|
const dir = path.join(tmpFolder, 'prepare'); |
42
|
|
|
const packer = new Packer({ |
43
|
|
|
dir, |
44
|
|
|
copy : [ [ 'tests/init.js', 'tests-init.js' ] ] |
45
|
|
|
}); |
46
|
|
|
|
47
|
|
|
await packer.ready; |
48
|
|
|
await packer.packModule(); |
49
|
|
|
await packer.prepare(); |
50
|
|
|
|
51
|
|
|
assert.isTrue(await fs.exists(path.join(dir, 'package.json')), 'package.json exists'); |
52
|
|
|
}); |
53
|
|
|
|
54
|
|
|
|
55
|
|
|
after(async function () { |
56
|
|
|
await factory.cleanTmpFolder(); |
57
|
|
|
}); |
58
|
|
|
|