-
-
Notifications
You must be signed in to change notification settings - Fork 528
Expand file tree
/
Copy pathinit.test.js
More file actions
158 lines (146 loc) · 5.19 KB
/
init.test.js
File metadata and controls
158 lines (146 loc) · 5.19 KB
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
const Support = require(__dirname + '/support');
const helpers = require(__dirname + '/support/helpers');
const gulp = require('gulp');
['init'].forEach((flag) => {
describe(Support.getTestDialectTeaser(flag), () => {
(function (folders) {
folders.forEach((folder) => {
it('creates "' + folder + '"', (done) => {
let sourcePath = Support.resolveSupportPath('tmp');
let file = folder;
if (folder.indexOf('/') > -1) {
const split = folder.split('/');
file = split.pop();
sourcePath = Support.resolveSupportPath('tmp', split.join('/'));
}
gulp
.src(Support.resolveSupportPath('tmp'))
.pipe(helpers.clearDirectory())
.pipe(helpers.runCli(flag))
.pipe(
helpers.teardown(() => {
gulp
.src(sourcePath)
.pipe(helpers.listFiles())
.pipe(helpers.ensureContent(file))
.pipe(helpers.teardown(done));
})
);
});
});
})([
'config',
'config/config.json',
'migrations',
'models',
'models/index.js',
]);
it('creates a custom config folder', (done) => {
gulp
.src(Support.resolveSupportPath('tmp'))
.pipe(helpers.clearDirectory())
.pipe(helpers.runCli(flag + ' --config my-config/config/config.json'))
.pipe(helpers.listFiles())
.pipe(helpers.ensureContent('my-config'))
.pipe(helpers.teardown(done));
});
it('creates a custom migrations folder', (done) => {
gulp
.src(Support.resolveSupportPath('tmp'))
.pipe(helpers.clearDirectory())
.pipe(helpers.runCli(flag + ' --migrations-path ./db/migrate'))
.pipe(helpers.listFiles())
.pipe(helpers.ensureContent('db'))
.pipe(helpers.teardown(done));
});
it('creates a custom config file', (done) => {
gulp
.src(Support.resolveSupportPath('tmp'))
.pipe(helpers.clearDirectory())
.pipe(helpers.runCli(flag + ' --config config/database.json'))
.pipe(
helpers.teardown(() => {
gulp
.src(Support.resolveSupportPath('tmp', 'config'))
.pipe(helpers.listFiles())
.pipe(helpers.ensureContent('database.json'))
.pipe(helpers.teardown(done));
})
);
});
it('creates a custom models folder', (done) => {
gulp
.src(Support.resolveSupportPath('tmp'))
.pipe(helpers.clearDirectory())
.pipe(helpers.runCli(flag + ' --models-path daos'))
.pipe(helpers.listFiles())
.pipe(helpers.ensureContent('daos'))
.pipe(helpers.teardown(done));
});
describe('models/index.js', () => {
it('correctly injects the reference to the default config file', (done) => {
gulp
.src(Support.resolveSupportPath('tmp'))
.pipe(helpers.clearDirectory())
.pipe(helpers.runCli(flag))
.pipe(
helpers.teardown(() => {
gulp
.src(Support.resolveSupportPath('tmp', 'models'))
.pipe(helpers.readFile('index.js'))
.pipe(
helpers.ensureContent("__dirname + '/../config/config.json'")
)
.pipe(helpers.teardown(done));
})
);
});
it('correctly injects the reference to the custom config file', (done) => {
gulp
.src(Support.resolveSupportPath('tmp'))
.pipe(helpers.clearDirectory())
.pipe(helpers.runCli(flag + ' --config my/configuration-file.json'))
.pipe(
helpers.teardown(() => {
gulp
.src(Support.resolveSupportPath('tmp', 'models'))
.pipe(helpers.readFile('index.js'))
.pipe(
helpers.ensureContent(
"__dirname + '/../my/configuration-file.json'"
)
)
.pipe(helpers.teardown(done));
})
);
});
});
it('does not put JSON content in dynamic custom configuration file', (done) => {
gulp
.src(Support.resolveSupportPath('tmp'))
.pipe(helpers.clearDirectory())
.pipe(helpers.runCli(flag + ' --config config/database.js'))
.pipe(
helpers.teardown(() => {
gulp
.src(Support.resolveSupportPath('tmp', 'config'))
.pipe(helpers.readFile('database.js'))
.pipe(helpers.ensureContent('module.exports'))
.pipe(helpers.ensureContent('process.env'))
.pipe(helpers.teardown(done));
})
);
});
it('does not overwrite an existing config.json file', (done) => {
gulp
.src(Support.resolveSupportPath('tmp'))
.pipe(helpers.clearDirectory())
.pipe(helpers.runCli(flag))
.pipe(helpers.overwriteFile('foo', 'config/config.json'))
.pipe(helpers.runCli(flag, { exitCode: 1 }))
.pipe(helpers.readFile('config/config.json'))
.pipe(helpers.ensureContent('foo'))
.pipe(helpers.teardown(done));
});
});
});