-
Notifications
You must be signed in to change notification settings - Fork 3
/
test.js
101 lines (74 loc) · 2.93 KB
/
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
const path = require('path');
const mockFs = require('mock-fs');
const mockRequire = require('mock-require');
const expect = require('chai').expect;
const {readFile} = require('fs-extra');
const {getStations, loadStationByName} = require('./lib/station');
const {createFile, createFilesByList} = require('./lib/wizard');
describe('lib/station', () => {
describe('getStations', () => {
afterEach(() => {
mockFs.restore();
});
it('returns array', async () => {
mockFs({
'.takeoff/custom-station': {}
});
const stations = await getStations();
expect(stations).to.be.a('array');
});
it('returns empty array if .takeoff folder doesnt exist ', async () => {
mockFs({});
const stations = await getStations();
expect(stations).to.deep.equal([]);
});
});
describe('loadStationByName', () => {
const stationsPath = path.resolve(process.cwd(), '.takeoff');
const sampleStation = path.resolve(stationsPath, 'custom-station', '__station.js');
const mockRequireStationPath = path.resolve(__dirname, '.takeoff', 'custom-station', '__station.js');
beforeEach(() => {
mockFs({
[sampleStation]: {},
});
mockRequire(mockRequireStationPath, {mockedType: 'custom-station'});
});
afterEach(() => {
mockFs.restore();
});
it('returns a object', async () => {
const station = await loadStationByName({name: 'custom-station', stationsPath});
expect(station).to.be.a('object');
});
it('returns station information from station', async () => {
const station = await loadStationByName({name: 'custom-station', stationsPath});
expect(station.mockedType).to.equal('custom-station');
});
});
});
describe('lib/wizard', () => {
beforeEach(() => mockFs());
afterEach(() => mockFs.restore());
describe('createFile', () => {
it('creates a file with specific content', async () => {
const createFileContent = 'This is my uniq content which i expect to be in the file';
const createFileName = 'my/test/file.js';
await createFile({filename: createFileName, template: createFileContent});
const readContentFile = await readFile(createFileName, 'utf8');
expect(readContentFile).to.equal(createFileContent);
});
});
describe('createFilesByList', () => {
it('creates a list of files in a row', async () => {
await createFilesByList([{
filename: 'my/test/file.js', template: 'This is my uniq content which i expect to be in the file'
}, {
filename: 'some-file.jsx', template: '<div>jsx?</div>'
}]);
const readMyTestFileContent = await readFile('my/test/file.js', 'utf8');
expect(readMyTestFileContent).to.equal('This is my uniq content which i expect to be in the file');
const readSomeFileJSXContent = await readFile('some-file.jsx', 'utf8');
expect(readSomeFileJSXContent).to.equal('<div>jsx?</div>');
});
});
});