-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.test.js
61 lines (52 loc) · 1.5 KB
/
index.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
57
58
59
60
61
const fs = require('fs-extra');
const path = require('path');
const gitCache = require('./index');
jest.setTimeout(1000 * 30);
describe('testing template-down', () => {
const git = 'pspgbhu/eslint-g';
const target = '__target__';
const cacheDir = '__demo__';
const zipTarget = '__zip__';
test('testing property: git, target, cacheDir', done => {
gitCache({
git,
target,
cacheDir,
}).then(() => {
done();
});
});
test('testing property: way', done => {
gitCache({
git,
target: zipTarget,
way: 'zip',
}).then(() => {
done();
});
});
test('testing property: offline', done => {
// create a file as the flag,if the flag file exists in the newly created target folder,
// then means that the target folder is directly copied cached files.
fs.writeFileSync(path.resolve(__dirname, cacheDir, 'flag.flag'));
gitCache({ git, target, cacheDir, }).then(() => {
if (fs.existsSync(path.resolve(__dirname, target, 'flag.flag'))) {
done();
} else {
throw new Error('dont exists flag file');
}
});
});
test('it should filter the .git folder', done => {
if (fs.existsSync(path.resolve(__dirname, target, '.git'))) {
throw new Error('.git folder is not be filtered');
} else {
done();
}
});
afterAll(() => {
fs.remove(path.resolve(__dirname, target));
fs.remove(path.resolve(__dirname, zipTarget));
fs.remove(path.resolve(__dirname, cacheDir));
});
});