js-build-tools 2.2.2 → 2.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -7
- package/dist/build.js +16 -3
- package/dist/build.min.js +1 -1
- package/dist/test-helpers/setUp.js +11 -8
- package/functions/build.js +25 -9
- package/functions/build.test.js +283 -39
- package/functions/partials/addToReadme.test.js +9 -4
- package/functions/partials/clean.test.js +2 -1
- package/functions/test-helpers/setUp.js +11 -8
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -168,7 +168,7 @@ Export these functions to your own project in order to customize your build pipe
|
|
|
168
168
|
* [.bundleMinify()](#module_js-build-tools.bundleMinify) ⇒ <code>\*</code>
|
|
169
169
|
* [.bundleLint()](#module_js-build-tools.bundleLint) ⇒ <code>stream.Stream</code>
|
|
170
170
|
* [.bundle()](#module_js-build-tools.bundle) ⇒ <code>stream.Stream</code>
|
|
171
|
-
* [.build(
|
|
171
|
+
* [.build()](#module_js-build-tools.build) ⇒ <code>stream.Stream</code>
|
|
172
172
|
|
|
173
173
|
<a name="module_js-build-tools.compileReadme"></a>
|
|
174
174
|
|
|
@@ -255,15 +255,10 @@ Starting at the distribution entry point, bundle all the files into a single fil
|
|
|
255
255
|
**Kind**: static method of [<code>js-build-tools</code>](#module_js-build-tools)
|
|
256
256
|
<a name="module_js-build-tools.build"></a>
|
|
257
257
|
|
|
258
|
-
### js-build-tools.build(
|
|
258
|
+
### js-build-tools.build() ⇒ <code>stream.Stream</code>
|
|
259
259
|
Runs several processes to build and validate the project.
|
|
260
260
|
|
|
261
261
|
**Kind**: static method of [<code>js-build-tools</code>](#module_js-build-tools)
|
|
262
|
-
|
|
263
|
-
| Param | Type | Default |
|
|
264
|
-
| --- | --- | --- |
|
|
265
|
-
| [done] | <code>function</code> | <code></code> |
|
|
266
|
-
|
|
267
262
|
<a name="module_gulpConfig"></a>
|
|
268
263
|
|
|
269
264
|
## gulpConfig
|
package/dist/build.js
CHANGED
|
@@ -7,7 +7,6 @@ var _require = require('./partials')
|
|
|
7
7
|
var clean = _require.clean
|
|
8
8
|
var distSeries = _require.distSeries
|
|
9
9
|
var compileReadme = require('./compileReadme')
|
|
10
|
-
var dist = require('./dist')
|
|
11
10
|
var distLint = require('./distLint')
|
|
12
11
|
var distMinify = require('./distMinify')
|
|
13
12
|
var _require2 = require('gulp')
|
|
@@ -20,11 +19,25 @@ var testFull = require('./testFull')
|
|
|
20
19
|
* Runs several processes to build and validate the project.
|
|
21
20
|
* Cleans, distributes (lint and minify), bundles (lint and minify), creates the readme, then runs the tests.
|
|
22
21
|
* @memberOf module:js-build-tools
|
|
23
|
-
* @param {function} [done=null]
|
|
24
22
|
* @returns {stream.Stream}
|
|
25
23
|
*/
|
|
26
24
|
var build = function build () {
|
|
27
25
|
var done = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null
|
|
28
|
-
|
|
26
|
+
var distLintMinify = parallel(distLint, distMinify)
|
|
27
|
+
var bundleLintMinify = parallel(bundleLint, bundleMinify)
|
|
28
|
+
var buildActions = [clean, distSeries(), distLintMinify]
|
|
29
|
+
if (gulpConfig.get('useTsConfig')) {
|
|
30
|
+
buildActions.push(compileReadme)
|
|
31
|
+
}
|
|
32
|
+
if (!gulpConfig.get('nodeOnly')) {
|
|
33
|
+
buildActions.push(bundle)
|
|
34
|
+
buildActions.push(bundleLintMinify)
|
|
35
|
+
}
|
|
36
|
+
var runActions = [series.apply(void 0, buildActions)]
|
|
37
|
+
if (!gulpConfig.get('useTsConfig')) {
|
|
38
|
+
runActions.push(compileReadme)
|
|
39
|
+
}
|
|
40
|
+
runActions.push(testFull)
|
|
41
|
+
return parallel.apply(void 0, runActions)(done)
|
|
29
42
|
}
|
|
30
43
|
module.exports = build
|
package/dist/build.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var bundle=require("./bundle"),bundleLint=require("./bundleLint"),bundleMinify=require("./bundleMinify"),_require=require("./partials"),clean=_require.clean,distSeries=_require.distSeries,compileReadme=require("./compileReadme"),
|
|
1
|
+
"use strict";var bundle=require("./bundle"),bundleLint=require("./bundleLint"),bundleMinify=require("./bundleMinify"),_require=require("./partials"),clean=_require.clean,distSeries=_require.distSeries,compileReadme=require("./compileReadme"),distLint=require("./distLint"),distMinify=require("./distMinify"),_require2=require("gulp"),parallel=_require2.parallel,series=_require2.series,gulpConfig=require("../gulp.config.js"),testFull=require("./testFull"),build=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null,i=parallel(distLint,distMinify),l=parallel(bundleLint,bundleMinify),r=[clean,distSeries(),i];gulpConfig.get("useTsConfig")&&r.push(compileReadme),gulpConfig.get("nodeOnly")||(r.push(bundle),r.push(l));var u=[series.apply(void 0,r)];return gulpConfig.get("useTsConfig")||u.push(compileReadme),u.push(testFull),parallel.apply(void 0,u)(e)};module.exports=build;
|
|
@@ -42,18 +42,21 @@ var setDefaults = function setDefaults() {
|
|
|
42
42
|
var testDir = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'test-temp';
|
|
43
43
|
tempDir = "".concat(testDir, "/");
|
|
44
44
|
srcPath = "".concat(tempDir, "src");
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
gulpConfig.set('
|
|
48
|
-
gulpConfig.set('
|
|
49
|
-
gulpConfig.set('
|
|
45
|
+
var distPath = "".concat(tempDir, "dist");
|
|
46
|
+
var browserPath = "".concat(tempDir, "browser");
|
|
47
|
+
gulpConfig.set('browserPath', browserPath);
|
|
48
|
+
gulpConfig.set('cleanPaths', [distPath, browserPath]);
|
|
49
|
+
gulpConfig.set('distMain', "".concat(distPath, "/main"));
|
|
50
|
+
gulpConfig.set('distPath', distPath);
|
|
51
|
+
gulpConfig.set('distSearch', "".concat(distPath, "/**/*.js"));
|
|
50
52
|
gulpConfig.set('readmeTemplate', "".concat(tempDir, "MAIN.md"));
|
|
51
53
|
gulpConfig.set('readmePath', tempDir);
|
|
54
|
+
gulpConfig.set('readmeSearch', "".concat(srcPath, "/**/!(*.test).js"));
|
|
52
55
|
gulpConfig.set('rootPath', tempDir);
|
|
53
56
|
gulpConfig.set('srcPath', srcPath);
|
|
54
|
-
gulpConfig.set('srcSearch', "".concat(
|
|
55
|
-
gulpConfig.set('tsSearch', "".concat(
|
|
56
|
-
gulpConfig.set('watchSearch', "".concat(
|
|
57
|
+
gulpConfig.set('srcSearch', "".concat(srcPath, "/**/!(*.test).js"));
|
|
58
|
+
gulpConfig.set('tsSearch', "".concat(srcPath, "/**/*.ts"));
|
|
59
|
+
gulpConfig.set('watchSearch', "".concat(srcPath, "/**/*.js"));
|
|
57
60
|
};
|
|
58
61
|
exports.setDefaults = setDefaults;
|
|
59
62
|
exports.gulpConfig = gulpConfig;
|
package/functions/build.js
CHANGED
|
@@ -3,7 +3,6 @@ const bundleLint = require('./bundleLint')
|
|
|
3
3
|
const bundleMinify = require('./bundleMinify')
|
|
4
4
|
const { clean, distSeries } = require('./partials')
|
|
5
5
|
const compileReadme = require('./compileReadme')
|
|
6
|
-
const dist = require('./dist')
|
|
7
6
|
const distLint = require('./distLint')
|
|
8
7
|
const distMinify = require('./distMinify')
|
|
9
8
|
const { parallel, series } = require('gulp')
|
|
@@ -14,15 +13,32 @@ const testFull = require('./testFull')
|
|
|
14
13
|
* Runs several processes to build and validate the project.
|
|
15
14
|
* Cleans, distributes (lint and minify), bundles (lint and minify), creates the readme, then runs the tests.
|
|
16
15
|
* @memberOf module:js-build-tools
|
|
17
|
-
* @param {function} [done=null]
|
|
18
16
|
* @returns {stream.Stream}
|
|
19
17
|
*/
|
|
20
|
-
const build = (done = null) =>
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
18
|
+
const build = (done = null) => {
|
|
19
|
+
const distLintMinify = parallel(distLint, distMinify)
|
|
20
|
+
const bundleLintMinify = parallel(bundleLint, bundleMinify)
|
|
21
|
+
const buildActions = [clean, distSeries(), distLintMinify]
|
|
22
|
+
if (gulpConfig.get('useTsConfig')) {
|
|
23
|
+
// For ts usage, we need to run the readme on the dist directly since that is where the .js files are located
|
|
24
|
+
buildActions.push(compileReadme)
|
|
25
|
+
}
|
|
26
|
+
if (!gulpConfig.get('nodeOnly')) {
|
|
27
|
+
// If not 'nodeOnly' then we also want to bundle for browser after we complete the dist directory
|
|
28
|
+
buildActions.push(bundle)
|
|
29
|
+
buildActions.push(bundleLintMinify)
|
|
30
|
+
}
|
|
31
|
+
const runActions = [
|
|
32
|
+
series(...buildActions),
|
|
33
|
+
]
|
|
34
|
+
if (!gulpConfig.get('useTsConfig')) {
|
|
35
|
+
// Since we didn't run this in series after dist because of typescript, we need to run it now. Potentially faster here.
|
|
36
|
+
runActions.push(compileReadme)
|
|
37
|
+
}
|
|
38
|
+
runActions.push(testFull)
|
|
39
|
+
return parallel(
|
|
40
|
+
...runActions
|
|
41
|
+
)(done)
|
|
42
|
+
}
|
|
27
43
|
|
|
28
44
|
module.exports = build
|
package/functions/build.test.js
CHANGED
|
@@ -1,59 +1,303 @@
|
|
|
1
|
-
const
|
|
1
|
+
const fs = require('fs')
|
|
2
|
+
const setUp = require('./test-helpers/setUp')
|
|
3
|
+
setUp.setDefaults('test-build')
|
|
2
4
|
const gulpConfig = setUp.gulpConfig
|
|
3
5
|
const build = require('./build')
|
|
4
|
-
const
|
|
5
|
-
const bundleLint = require('./bundleLint')
|
|
6
|
-
const bundleMinify = require('./bundleMinify')
|
|
7
|
-
const { clean, distSeries } = require('./partials')
|
|
8
|
-
const compileReadme = require('./compileReadme')
|
|
9
|
-
const dist = require('./dist')
|
|
10
|
-
const distLint = require('./distLint')
|
|
11
|
-
const distMinify = require('./distMinify')
|
|
6
|
+
const clean = require('./partials/clean')
|
|
12
7
|
const testFull = require('./testFull')
|
|
8
|
+
const { countMatches } = require('./testHelpers')
|
|
13
9
|
|
|
14
10
|
const genericFunction = () => Promise.resolve(true)
|
|
15
|
-
|
|
16
|
-
jest.mock('./bundleLint', () => jest.fn(genericFunction))
|
|
17
|
-
jest.mock('./bundleMinify', () => jest.fn(genericFunction))
|
|
11
|
+
|
|
18
12
|
jest.mock('./partials/clean', () => jest.fn(genericFunction))
|
|
19
|
-
jest.mock('./compileReadme', () => jest.fn(genericFunction))
|
|
20
|
-
jest.mock('./dist', () => jest.fn(genericFunction))
|
|
21
|
-
jest.mock('./distLint', () => jest.fn(genericFunction))
|
|
22
|
-
jest.mock('./distMinify', () => jest.fn(genericFunction))
|
|
23
|
-
jest.mock('./partials/distSeries', () => jest.fn(() => genericFunction))
|
|
24
13
|
jest.mock('./testFull', () => jest.fn(genericFunction))
|
|
25
14
|
|
|
15
|
+
const file1Typescript = '/**\n' +
|
|
16
|
+
' * Console log out a greeting with given input.\n' +
|
|
17
|
+
' * @param {string} input\n' +
|
|
18
|
+
' */\n' +
|
|
19
|
+
'const file1 = (input: string): void => console.log(`Hello from file1 with ${input}`)\n' +
|
|
20
|
+
'\n' +
|
|
21
|
+
'module.exports = file1\n'
|
|
22
|
+
|
|
23
|
+
const file1Contents = '/**\n' +
|
|
24
|
+
' * Console log out a greeting with given input.\n' +
|
|
25
|
+
' * @param {string} input\n' +
|
|
26
|
+
' */\n' +
|
|
27
|
+
'const file1 = input => console.log(`Hello from file1 with ${input}`)\n' +
|
|
28
|
+
'\n' +
|
|
29
|
+
'module.exports = file1\n'
|
|
30
|
+
|
|
31
|
+
const file2Typescript = '/**\n' +
|
|
32
|
+
' * Farewell with a summation of two numbers returned.\n' +
|
|
33
|
+
' * @param {number} a\n' +
|
|
34
|
+
' * @param {number} b\n' +
|
|
35
|
+
' * @returns {number}\n' +
|
|
36
|
+
' */\n' +
|
|
37
|
+
'const file2 = (a: number, b: number): number => {\n' +
|
|
38
|
+
' const sum = a + b\n' +
|
|
39
|
+
' console.log(`Good-bye from file2 with sum ${sum}`)\n' +
|
|
40
|
+
' return sum\n' +
|
|
41
|
+
'}\n' +
|
|
42
|
+
'\n' +
|
|
43
|
+
'module.exports = file2\n'
|
|
44
|
+
|
|
45
|
+
const file2Contents = '/**\n' +
|
|
46
|
+
' * Farewell with a summation of two numbers returned.\n' +
|
|
47
|
+
' * @param {number} a\n' +
|
|
48
|
+
' * @param {number} b\n' +
|
|
49
|
+
' * @returns {number}\n' +
|
|
50
|
+
' */\n' +
|
|
51
|
+
'const file2 = (a, b) => {\n' +
|
|
52
|
+
' const sum = a + b\n' +
|
|
53
|
+
' console.log(`Good-bye from file2 with sum ${sum}`)\n' +
|
|
54
|
+
' return sum\n' +
|
|
55
|
+
'}\n' +
|
|
56
|
+
'\n' +
|
|
57
|
+
'module.exports = file2\n'
|
|
58
|
+
|
|
59
|
+
const mainTypescript = '/**\n' +
|
|
60
|
+
' * A salutation and summation.\n' +
|
|
61
|
+
' * @param {number} a\n' +
|
|
62
|
+
' * @param {number} b\n' +
|
|
63
|
+
' * @returns {number}\n' +
|
|
64
|
+
' */\n' +
|
|
65
|
+
'const main = (a: number, b: number): number => {\n' +
|
|
66
|
+
' const sum = a + b\n' +
|
|
67
|
+
' console.log(`Greetings from typescript ${sum}`)\n' +
|
|
68
|
+
' return sum\n' +
|
|
69
|
+
'}\n' +
|
|
70
|
+
'\n' +
|
|
71
|
+
'module.exports = main\n'
|
|
72
|
+
|
|
73
|
+
const mainFileContents = '/**\n' +
|
|
74
|
+
' * Some test functions for usage with build tests.\n' +
|
|
75
|
+
' * @file\n' +
|
|
76
|
+
' * @author John Doe <john.doe@example.com>\n' +
|
|
77
|
+
' * @version 1.0.0\n' +
|
|
78
|
+
' * @module test-build\n' +
|
|
79
|
+
' */\n' +
|
|
80
|
+
'\n' +
|
|
81
|
+
'const file1 = require(\'./sources/file1\')\n' +
|
|
82
|
+
'const file2 = require(\'./sources/file2\')\n' +
|
|
83
|
+
'\n' +
|
|
84
|
+
'module.exports = {\n' +
|
|
85
|
+
' file1,\n' +
|
|
86
|
+
' file2,\n' +
|
|
87
|
+
'}\n'
|
|
88
|
+
|
|
89
|
+
const mainMd = '# Welcome\n' +
|
|
90
|
+
'This is the top of the README.md.\n' +
|
|
91
|
+
'\n'
|
|
92
|
+
|
|
93
|
+
const tsConfigContents = '{\n' +
|
|
94
|
+
' "files": ["test-build/src/**/*.ts"],\n' +
|
|
95
|
+
' "compilerOptions": {\n' +
|
|
96
|
+
' "noImplicitAny": true,\n' +
|
|
97
|
+
' "target": "es5"\n' +
|
|
98
|
+
' }\n' +
|
|
99
|
+
'}'
|
|
100
|
+
|
|
101
|
+
beforeEach(
|
|
102
|
+
() => setUp.beforeEach()
|
|
103
|
+
.then(
|
|
104
|
+
async () => {
|
|
105
|
+
const srcPath = gulpConfig.get('srcPath')
|
|
106
|
+
const readmePath = gulpConfig.get('readmePath')
|
|
107
|
+
const sourcesPath = `${srcPath}/sources`
|
|
108
|
+
await fs.mkdirSync(sourcesPath)
|
|
109
|
+
return fs.writeFileSync(`${readmePath}/MAIN.md`, mainMd)
|
|
110
|
+
}
|
|
111
|
+
)
|
|
112
|
+
)
|
|
113
|
+
|
|
114
|
+
afterEach(setUp.afterEach)
|
|
115
|
+
|
|
26
116
|
describe('build', () => {
|
|
27
|
-
test('when nodeOnly true: calls clean,
|
|
117
|
+
test('when nodeOnly true: calls clean, distSeries, distLint, distMinify, compileReadme, testFull', done => {
|
|
118
|
+
const srcPath = gulpConfig.get('srcPath')
|
|
119
|
+
const sourcesPath = `${srcPath}/sources`
|
|
120
|
+
const distPath = gulpConfig.get('distPath')
|
|
121
|
+
const distSourcesPath = `${distPath}/sources`
|
|
122
|
+
const readmePath = gulpConfig.get('readmePath')
|
|
123
|
+
const readmeFile = gulpConfig.get('readmeFile')
|
|
124
|
+
fs.writeFileSync(`${sourcesPath}/file1.js`, file1Contents)
|
|
125
|
+
fs.writeFileSync(`${sourcesPath}/file2.js`, file2Contents)
|
|
126
|
+
fs.writeFileSync(`${srcPath}/main.js`, mainFileContents)
|
|
28
127
|
gulpConfig.set('nodeOnly', true)
|
|
29
|
-
expect.assertions(
|
|
30
|
-
build()
|
|
31
|
-
|
|
128
|
+
expect.assertions(20)
|
|
129
|
+
build(() => {
|
|
130
|
+
// Called 'clean'
|
|
32
131
|
expect(clean).toHaveBeenCalled()
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
expect(
|
|
36
|
-
|
|
132
|
+
|
|
133
|
+
// Created dist directory (distSeries)
|
|
134
|
+
expect(fs.existsSync(distPath)).toBeTruthy()
|
|
135
|
+
|
|
136
|
+
// Minify the dist files (distMinify)
|
|
137
|
+
expect(fs.existsSync(`${distPath}/main.min.js`)).toBeTruthy()
|
|
138
|
+
const babelifiedMain = fs.readFileSync(`${distPath}/main.js`).toString()
|
|
139
|
+
// Used single quotes because of distLint
|
|
140
|
+
expect(countMatches(babelifiedMain, '\'use strict\'')).toEqual(1)
|
|
141
|
+
|
|
142
|
+
expect(fs.existsSync(`${distSourcesPath}/file1.min.js`)).toBeTruthy()
|
|
143
|
+
const babelifiedFile1 = fs.readFileSync(`${distSourcesPath}/file1.js`).toString()
|
|
144
|
+
expect(countMatches(babelifiedFile1, '\'use strict\'')).toEqual(1)
|
|
145
|
+
expect(countMatches(babelifiedFile1, 'const ')).toEqual(0)
|
|
146
|
+
expect(countMatches(babelifiedFile1, 'var ')).toEqual(1)
|
|
147
|
+
expect(countMatches(babelifiedFile1, 'function ')).toEqual(1)
|
|
148
|
+
expect(countMatches(babelifiedFile1, 'return ')).toEqual(1)
|
|
149
|
+
|
|
150
|
+
expect(fs.existsSync(`${distSourcesPath}/file2.min.js`)).toBeTruthy()
|
|
151
|
+
const babelifiedFile2 = fs.readFileSync(`${distSourcesPath}/file2.js`).toString()
|
|
152
|
+
expect(countMatches(babelifiedFile2, '\'use strict\'')).toEqual(1)
|
|
153
|
+
expect(countMatches(babelifiedFile2, 'const ')).toEqual(0)
|
|
154
|
+
expect(countMatches(babelifiedFile2, 'var ')).toEqual(2)
|
|
155
|
+
expect(countMatches(babelifiedFile2, 'function ')).toEqual(1)
|
|
156
|
+
|
|
157
|
+
// Generated README.md (compileReadme)
|
|
158
|
+
const readmeContents = fs.readFileSync(`${readmePath}/${readmeFile}`).toString()
|
|
159
|
+
expect(countMatches(readmeContents, mainMd)).toEqual(1)
|
|
160
|
+
expect(countMatches(readmeContents, 'test-build')).toEqual(4)
|
|
161
|
+
expect(countMatches(readmeContents, 'file1')).toEqual(4)
|
|
162
|
+
expect(countMatches(readmeContents, 'file2')).toEqual(4)
|
|
163
|
+
|
|
164
|
+
// Ran 'testFull'
|
|
37
165
|
expect(testFull).toHaveBeenCalled()
|
|
38
166
|
done()
|
|
39
|
-
}
|
|
40
|
-
})
|
|
167
|
+
})
|
|
168
|
+
}, 30000)
|
|
41
169
|
|
|
42
170
|
test('when nodeOnly false: calls clean, distSeries, distLint, distMinify, bundle, bundleLint, bundleMinify, compileReadme, testFull', done => {
|
|
171
|
+
const srcPath = gulpConfig.get('srcPath')
|
|
172
|
+
const sourcesPath = `${srcPath}/sources`
|
|
173
|
+
const distPath = gulpConfig.get('distPath')
|
|
174
|
+
const browserFile = gulpConfig.get('browserName')
|
|
175
|
+
const browserPath = gulpConfig.get('browserPath')
|
|
176
|
+
const bundledFile = `${browserPath}/${browserFile}.js`
|
|
177
|
+
const readmePath = gulpConfig.get('readmePath')
|
|
178
|
+
const readmeFile = gulpConfig.get('readmeFile')
|
|
179
|
+
fs.writeFileSync(`${sourcesPath}/file1.js`, file1Contents)
|
|
180
|
+
fs.writeFileSync(`${sourcesPath}/file2.js`, file2Contents)
|
|
181
|
+
fs.writeFileSync(`${srcPath}/main.js`, mainFileContents)
|
|
43
182
|
gulpConfig.set('nodeOnly', false)
|
|
44
|
-
expect.assertions(
|
|
45
|
-
build()
|
|
46
|
-
|
|
183
|
+
expect.assertions(13)
|
|
184
|
+
build(() => {
|
|
185
|
+
// Called 'clean'
|
|
47
186
|
expect(clean).toHaveBeenCalled()
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
expect(
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
expect(
|
|
54
|
-
|
|
187
|
+
|
|
188
|
+
// Created dist directory (distSeries)
|
|
189
|
+
expect(fs.existsSync(distPath)).toBeTruthy()
|
|
190
|
+
|
|
191
|
+
// Minify the dist files (distMinify)
|
|
192
|
+
expect(fs.existsSync(`${distPath}/main.min.js`)).toBeTruthy()
|
|
193
|
+
const babelifiedMain = fs.readFileSync(`${distPath}/main.js`).toString()
|
|
194
|
+
// Used single quotes because of distLint
|
|
195
|
+
expect(countMatches(babelifiedMain, '\'use strict\'')).toEqual(1)
|
|
196
|
+
|
|
197
|
+
// Created browser directory (bundle)
|
|
198
|
+
expect(fs.existsSync(browserPath)).toBeTruthy()
|
|
199
|
+
|
|
200
|
+
// Minify the browser files (bundleMinify)
|
|
201
|
+
expect(fs.existsSync(`${browserPath}/${browserFile}.min.js`)).toBeTruthy()
|
|
202
|
+
const bundledContents = fs.readFileSync(bundledFile).toString()
|
|
203
|
+
expect(countMatches(bundledContents, 'file1')).toEqual(9)
|
|
204
|
+
expect(countMatches(bundledContents, 'file2')).toEqual(9)
|
|
205
|
+
|
|
206
|
+
// Generated README.md (compileReadme)
|
|
207
|
+
const readmeContents = fs.readFileSync(`${readmePath}/${readmeFile}`).toString()
|
|
208
|
+
expect(countMatches(readmeContents, mainMd)).toEqual(1)
|
|
209
|
+
expect(countMatches(readmeContents, 'test-build')).toEqual(4)
|
|
210
|
+
expect(countMatches(readmeContents, 'file1')).toEqual(4)
|
|
211
|
+
expect(countMatches(readmeContents, 'file2')).toEqual(4)
|
|
212
|
+
|
|
213
|
+
// Ran 'testFull'
|
|
214
|
+
expect(testFull).toHaveBeenCalled()
|
|
215
|
+
done()
|
|
216
|
+
})
|
|
217
|
+
}, 30000)
|
|
218
|
+
|
|
219
|
+
test('when nodeOnly true and useTsConfig set: calls clean, tsFor, distFor, distLint, distMinify, compileReadme, testFull', done => {
|
|
220
|
+
const srcPath = gulpConfig.get('srcPath')
|
|
221
|
+
const rootPath = gulpConfig.get('rootPath')
|
|
222
|
+
const tsConfig = `${rootPath}/tsconfig.json`
|
|
223
|
+
const distPath = gulpConfig.get('distPath')
|
|
224
|
+
const readmePath = gulpConfig.get('readmePath')
|
|
225
|
+
const readmeFile = gulpConfig.get('readmeFile')
|
|
226
|
+
fs.writeFileSync(`${srcPath}/main.ts`, mainTypescript)
|
|
227
|
+
fs.writeFileSync(tsConfig, tsConfigContents)
|
|
228
|
+
gulpConfig.set('nodeOnly', true)
|
|
229
|
+
gulpConfig.set('useTsConfig', tsConfig)
|
|
230
|
+
gulpConfig.set('readmeSearch', `${distPath}/**/*.js`)
|
|
231
|
+
expect.assertions(7)
|
|
232
|
+
build(() => {
|
|
233
|
+
// Called 'clean'
|
|
234
|
+
expect(clean).toHaveBeenCalled()
|
|
235
|
+
|
|
236
|
+
// Created dist directory (distSeries)
|
|
237
|
+
expect(fs.existsSync(distPath)).toBeTruthy()
|
|
238
|
+
|
|
239
|
+
// Minify the dist files (distMinify)
|
|
240
|
+
expect(fs.existsSync(`${distPath}/main.min.js`)).toBeTruthy()
|
|
241
|
+
const babelifiedMain = fs.readFileSync(`${distPath}/main.js`).toString()
|
|
242
|
+
// Used single quotes because of distLint
|
|
243
|
+
expect(countMatches(babelifiedMain, '\'use strict\'')).toEqual(1)
|
|
244
|
+
|
|
245
|
+
// Generated README.md (compileReadme)
|
|
246
|
+
const readmeContents = fs.readFileSync(`${readmePath}/${readmeFile}`).toString()
|
|
247
|
+
expect(countMatches(readmeContents, mainMd)).toEqual(1)
|
|
248
|
+
expect(countMatches(readmeContents, 'main')).toEqual(2)
|
|
249
|
+
|
|
250
|
+
// Ran 'testFull'
|
|
251
|
+
expect(testFull).toHaveBeenCalled()
|
|
252
|
+
done()
|
|
253
|
+
})
|
|
254
|
+
}, 30000)
|
|
255
|
+
|
|
256
|
+
test('when nodeOnly false and useTsConfig false: calls clean, tsFor, distFor, distLint, distMinify, bundle, bundleLint, bundleMinify, compileReadme, testFull', done => {
|
|
257
|
+
const srcPath = gulpConfig.get('srcPath')
|
|
258
|
+
const rootPath = gulpConfig.get('rootPath')
|
|
259
|
+
const tsConfig = `${rootPath}/tsconfig.json`
|
|
260
|
+
const distPath = gulpConfig.get('distPath')
|
|
261
|
+
const browserFile = gulpConfig.get('browserName')
|
|
262
|
+
const browserPath = gulpConfig.get('browserPath')
|
|
263
|
+
const bundledFile = `${browserPath}/${browserFile}.js`
|
|
264
|
+
const readmePath = gulpConfig.get('readmePath')
|
|
265
|
+
const readmeFile = gulpConfig.get('readmeFile')
|
|
266
|
+
fs.writeFileSync(`${srcPath}/main.ts`, mainTypescript)
|
|
267
|
+
fs.writeFileSync(tsConfig, tsConfigContents)
|
|
268
|
+
gulpConfig.set('nodeOnly', false)
|
|
269
|
+
gulpConfig.set('useTsConfig', tsConfig)
|
|
270
|
+
gulpConfig.set('readmeSearch', `${distPath}/**/*.js`)
|
|
271
|
+
expect.assertions(10)
|
|
272
|
+
build(() => {
|
|
273
|
+
// Called 'clean'
|
|
274
|
+
expect(clean).toHaveBeenCalled()
|
|
275
|
+
|
|
276
|
+
// Created dist directory (distSeries)
|
|
277
|
+
expect(fs.existsSync(distPath)).toBeTruthy()
|
|
278
|
+
|
|
279
|
+
// Minify the dist files (distMinify)
|
|
280
|
+
expect(fs.existsSync(`${distPath}/main.min.js`)).toBeTruthy()
|
|
281
|
+
const babelifiedMain = fs.readFileSync(`${distPath}/main.js`).toString()
|
|
282
|
+
// Used single quotes because of distLint
|
|
283
|
+
expect(countMatches(babelifiedMain, '\'use strict\'')).toEqual(1)
|
|
284
|
+
|
|
285
|
+
// Created browser directory (bundle)
|
|
286
|
+
expect(fs.existsSync(browserPath)).toBeTruthy()
|
|
287
|
+
|
|
288
|
+
// Minify the browser files (bundleMinify)
|
|
289
|
+
expect(fs.existsSync(`${browserPath}/${browserFile}.min.js`)).toBeTruthy()
|
|
290
|
+
const bundledContents = fs.readFileSync(bundledFile).toString()
|
|
291
|
+
expect(countMatches(bundledContents, 'main')).toEqual(3)
|
|
292
|
+
|
|
293
|
+
// Generated README.md (compileReadme)
|
|
294
|
+
const readmeContents = fs.readFileSync(`${readmePath}/${readmeFile}`).toString()
|
|
295
|
+
expect(countMatches(readmeContents, mainMd)).toEqual(1)
|
|
296
|
+
expect(countMatches(readmeContents, 'main')).toEqual(2)
|
|
297
|
+
|
|
298
|
+
// Ran 'testFull'
|
|
55
299
|
expect(testFull).toHaveBeenCalled()
|
|
56
300
|
done()
|
|
57
|
-
}
|
|
58
|
-
})
|
|
301
|
+
})
|
|
302
|
+
}, 30000)
|
|
59
303
|
})
|
|
@@ -5,9 +5,14 @@ const gulpConfig = setUp.gulpConfig
|
|
|
5
5
|
gulpConfig.set('srcSearch', 'test-temp/src/addToReadme.js')
|
|
6
6
|
const addToReadme = require('./addToReadme')
|
|
7
7
|
|
|
8
|
-
const rawContents = '
|
|
9
|
-
'
|
|
10
|
-
'}'
|
|
8
|
+
const rawContents = '/**\n' +
|
|
9
|
+
' * Say hello with a given name.\n' +
|
|
10
|
+
' * @param {string} name\n' +
|
|
11
|
+
' * @returns {string}\n' +
|
|
12
|
+
' */\n' +
|
|
13
|
+
'const sayHello = name => `Hello from ${name}`\n' +
|
|
14
|
+
'\n' +
|
|
15
|
+
'module.exports = sayHello\n'
|
|
11
16
|
|
|
12
17
|
beforeEach(() => setUp.beforeEach()
|
|
13
18
|
.then(() => fs.writeFileSync(gulpConfig.get('srcPath') + '/addToReadme.js', rawContents)))
|
|
@@ -22,6 +27,6 @@ describe('addToReadme', () => {
|
|
|
22
27
|
await expect(fs.existsSync(readmeFilePath)).toBeTruthy()
|
|
23
28
|
const readme = await fs.readFileSync(readmeFilePath)
|
|
24
29
|
// At least the documentation will have the addToReadme documentation
|
|
25
|
-
await expect(readme.includes('
|
|
30
|
+
await expect(readme.includes('sayHello')).toBeTruthy()
|
|
26
31
|
})
|
|
27
32
|
})
|
|
@@ -2,6 +2,8 @@ const fs = require('fs')
|
|
|
2
2
|
const setUp = require('../test-helpers/setUp')
|
|
3
3
|
setUp.setDefaults('test-clean')
|
|
4
4
|
const gulpConfig = setUp.gulpConfig
|
|
5
|
+
const srcPath = gulpConfig.get('srcPath')
|
|
6
|
+
gulpConfig.set('cleanPaths', [srcPath])
|
|
5
7
|
const clean = require('./clean')
|
|
6
8
|
|
|
7
9
|
beforeEach(setUp.beforeEach)
|
|
@@ -11,7 +13,6 @@ afterEach(setUp.afterEach)
|
|
|
11
13
|
describe('clean', () => {
|
|
12
14
|
test('removes all contents of directories specified', async () => {
|
|
13
15
|
expect.assertions(2)
|
|
14
|
-
const srcPath = gulpConfig.get('srcPath')
|
|
15
16
|
expect(fs.readdirSync(srcPath)).toBeTruthy()
|
|
16
17
|
// Run the clean script to empty the directories
|
|
17
18
|
await clean()
|
|
@@ -15,18 +15,21 @@ let srcPath = `${tempDir}src`
|
|
|
15
15
|
const setDefaults = (testDir = 'test-temp') => {
|
|
16
16
|
tempDir = `${testDir}/`
|
|
17
17
|
srcPath = `${tempDir}src`
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
gulpConfig.set('
|
|
21
|
-
gulpConfig.set('
|
|
22
|
-
gulpConfig.set('
|
|
18
|
+
const distPath = `${tempDir}dist`
|
|
19
|
+
const browserPath = `${tempDir}browser`
|
|
20
|
+
gulpConfig.set('browserPath', browserPath)
|
|
21
|
+
gulpConfig.set('cleanPaths', [distPath, browserPath])
|
|
22
|
+
gulpConfig.set('distMain', `${distPath}/main`)
|
|
23
|
+
gulpConfig.set('distPath', distPath)
|
|
24
|
+
gulpConfig.set('distSearch', `${distPath}/**/*.js`)
|
|
23
25
|
gulpConfig.set('readmeTemplate', `${tempDir}MAIN.md`)
|
|
24
26
|
gulpConfig.set('readmePath', tempDir)
|
|
27
|
+
gulpConfig.set('readmeSearch', `${srcPath}/**/!(*.test).js`)
|
|
25
28
|
gulpConfig.set('rootPath', tempDir)
|
|
26
29
|
gulpConfig.set('srcPath', srcPath)
|
|
27
|
-
gulpConfig.set('srcSearch', `${
|
|
28
|
-
gulpConfig.set('tsSearch', `${
|
|
29
|
-
gulpConfig.set('watchSearch', `${
|
|
30
|
+
gulpConfig.set('srcSearch', `${srcPath}/**/!(*.test).js`)
|
|
31
|
+
gulpConfig.set('tsSearch', `${srcPath}/**/*.ts`)
|
|
32
|
+
gulpConfig.set('watchSearch', `${srcPath}/**/*.js`)
|
|
30
33
|
}
|
|
31
34
|
|
|
32
35
|
exports.setDefaults = setDefaults
|