js-build-tools 1.2.2 → 2.1.0
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 +590 -267
- package/dist/build.js +30 -23
- package/dist/build.min.js +1 -1
- package/dist/bundle.js +18 -15
- package/dist/bundle.min.js +1 -1
- package/dist/bundleLint.js +24 -20
- package/dist/bundleLint.min.js +1 -1
- package/dist/bundleMinify.js +16 -20
- package/dist/bundleMinify.min.js +1 -1
- package/dist/compileReadme.js +15 -13
- package/dist/compileReadme.min.js +1 -1
- package/dist/default.js +19 -14
- package/dist/default.min.js +1 -1
- package/dist/dist.js +14 -10
- package/dist/dist.min.js +1 -1
- package/dist/distLint.js +23 -20
- package/dist/distLint.min.js +1 -1
- package/dist/distMinify.js +15 -20
- package/dist/distMinify.min.js +1 -1
- package/dist/partials/addToReadme.js +25 -0
- package/dist/partials/beginWatcher.js +16 -0
- package/dist/partials/clean.js +21 -0
- package/dist/partials/distFor.js +23 -0
- package/dist/partials/distForSrc.js +16 -0
- package/dist/partials/distSeries.js +31 -0
- package/dist/partials/minifyFor.js +21 -0
- package/dist/partials/readmeTemplate.js +18 -0
- package/dist/partials/runOnChange.js +63 -0
- package/dist/partials/tsFor.js +24 -0
- package/dist/partials.js +33 -0
- package/dist/partials.min.js +1 -0
- package/dist/test-helpers/circularObject.js +50 -0
- package/dist/test-helpers/countMatches.js +16 -0
- package/dist/test-helpers/deepReferenceObject.js +20 -0
- package/dist/test-helpers/domItem.js +33 -0
- package/dist/test-helpers/jsonDom.js +20 -0
- package/dist/test-helpers/linkedList.js +23 -0
- package/dist/test-helpers/logObject.js +24 -0
- package/dist/test-helpers/multiReferenceObject.js +20 -0
- package/dist/test-helpers/nodeTree.js +28 -0
- package/dist/test-helpers/setUp.js +127 -0
- package/dist/testFull.js +24 -13
- package/dist/testFull.min.js +1 -1
- package/dist/testHelpers.js +33 -198
- package/dist/testHelpers.min.js +1 -1
- package/dist/testQuick.js +26 -15
- package/dist/testQuick.min.js +1 -1
- package/dist/typeScript.js +14 -0
- package/dist/typeScript.min.js +1 -0
- package/dist/watchFull.js +14 -21
- package/dist/watchFull.min.js +1 -1
- package/dist/watchTest.js +16 -14
- package/dist/watchTest.min.js +1 -1
- package/functions/build.js +28 -25
- package/functions/build.test.js +59 -0
- package/functions/bundle.js +17 -15
- package/functions/bundle.test.js +68 -0
- package/functions/bundleLint.js +19 -17
- package/functions/bundleLint.test.js +61 -0
- package/functions/bundleMinify.js +12 -15
- package/functions/bundleMinify.test.js +14 -0
- package/functions/compileReadme.js +11 -10
- package/functions/compileReadme.test.js +18 -0
- package/functions/default.js +14 -11
- package/functions/default.test.js +32 -0
- package/functions/dist.js +11 -9
- package/functions/dist.test.js +43 -0
- package/functions/distLint.js +19 -17
- package/functions/distLint.test.js +58 -0
- package/functions/distMinify.js +12 -15
- package/functions/distMinify.test.js +14 -0
- package/functions/partials/addToReadme.js +20 -0
- package/functions/partials/addToReadme.test.js +28 -0
- package/functions/partials/beginWatcher.js +12 -0
- package/functions/partials/beginWatcher.test.js +18 -0
- package/functions/partials/clean.js +14 -0
- package/functions/partials/clean.test.js +20 -0
- package/functions/partials/distFor.js +18 -0
- package/functions/partials/distFor.test.js +125 -0
- package/functions/partials/distForSrc.js +14 -0
- package/functions/partials/distForSrc.test.js +17 -0
- package/functions/partials/distSeries.js +21 -0
- package/functions/partials/distSeries.test.js +33 -0
- package/functions/partials/minifyFor.js +16 -0
- package/functions/partials/minifyFor.test.js +48 -0
- package/functions/partials/readmeTemplate.js +15 -0
- package/functions/partials/readmeTemplate.test.js +33 -0
- package/functions/partials/runOnChange.js +57 -0
- package/functions/partials/runOnChange.test.js +93 -0
- package/functions/partials/tsFor.js +21 -0
- package/functions/partials/tsFor.test.js +44 -0
- package/functions/partials.js +32 -0
- package/functions/partials.test.js +7 -0
- package/functions/test-helpers/circularObject.js +28 -0
- package/functions/test-helpers/circularObject.test.js +14 -0
- package/functions/test-helpers/countMatches.js +11 -0
- package/functions/test-helpers/countMatches.test.js +9 -0
- package/functions/test-helpers/deepReferenceObject.js +25 -0
- package/functions/test-helpers/deepReferenceObject.test.js +7 -0
- package/functions/test-helpers/domItem.js +31 -0
- package/functions/test-helpers/domItem.test.js +12 -0
- package/functions/test-helpers/jsonDom.js +16 -0
- package/functions/test-helpers/jsonDom.test.js +12 -0
- package/functions/test-helpers/linkedList.js +10 -0
- package/functions/test-helpers/linkedList.test.js +22 -0
- package/functions/test-helpers/logObject.js +18 -0
- package/functions/test-helpers/logObject.test.js +20 -0
- package/functions/test-helpers/multiReferenceObject.js +25 -0
- package/functions/test-helpers/multiReferenceObject.test.js +14 -0
- package/functions/test-helpers/nodeTree.js +11 -0
- package/functions/test-helpers/nodeTree.test.js +18 -0
- package/functions/test-helpers/setUp.js +67 -0
- package/functions/test-helpers/setUp.test.js +18 -0
- package/functions/testFull.js +20 -10
- package/functions/testFull.test.js +16 -0
- package/functions/testHelpers.js +27 -137
- package/functions/testHelpers.test.js +7 -100
- package/functions/testQuick.js +20 -10
- package/functions/testQuick.test.js +16 -0
- package/functions/typeScript.js +11 -0
- package/functions/typeScript.test.js +10 -0
- package/functions/watchFull.js +6 -12
- package/functions/watchFull.test.js +40 -0
- package/functions/watchTest.js +4 -2
- package/functions/watchTest.test.js +48 -0
- package/gulp.config.js +161 -16
- package/gulpfile.base.js +9 -0
- package/package.json +11 -11
- package/dist/addToReadme.js +0 -22
- package/dist/addToReadme.min.js +0 -1
- package/dist/clean.js +0 -11
- package/dist/clean.min.js +0 -1
- package/dist/distFor.js +0 -21
- package/dist/distFor.min.js +0 -1
- package/dist/readmeTemplate.js +0 -15
- package/dist/readmeTemplate.min.js +0 -1
- package/functions/addToReadme.js +0 -17
- package/functions/clean.js +0 -10
- package/functions/distFor.js +0 -15
- package/functions/readmeTemplate.js +0 -13
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sample object with deep references.
|
|
3
|
+
* @memberOf module:testHelpers
|
|
4
|
+
* @type {Object.<string, string|number|Object>}
|
|
5
|
+
*/
|
|
6
|
+
const deepReferenceObject = {
|
|
7
|
+
object1: {
|
|
8
|
+
name: 'someName',
|
|
9
|
+
object2: {
|
|
10
|
+
age: 12,
|
|
11
|
+
array1: [
|
|
12
|
+
'someString',
|
|
13
|
+
'anotherString'
|
|
14
|
+
]
|
|
15
|
+
},
|
|
16
|
+
array2: [
|
|
17
|
+
89,
|
|
18
|
+
32
|
|
19
|
+
]
|
|
20
|
+
},
|
|
21
|
+
title: 'Some Title',
|
|
22
|
+
item: 45
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
module.exports = deepReferenceObject
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sample of domItem child with nested child and optional details
|
|
3
|
+
* @memberOf module:testHelpers
|
|
4
|
+
* @type {Object.<string, string|number|Array|Object>}
|
|
5
|
+
*/
|
|
6
|
+
const domItem = [
|
|
7
|
+
{
|
|
8
|
+
attributes: { className: 'row', style: {} },
|
|
9
|
+
axis: 'y',
|
|
10
|
+
children: [
|
|
11
|
+
{
|
|
12
|
+
attributes: { style: {} },
|
|
13
|
+
axis: 'x',
|
|
14
|
+
children: [],
|
|
15
|
+
element: {},
|
|
16
|
+
eventListeners: {},
|
|
17
|
+
hasShip: false,
|
|
18
|
+
isHit: false,
|
|
19
|
+
parentItem: {},
|
|
20
|
+
point: {},
|
|
21
|
+
tagName: 'div'
|
|
22
|
+
}
|
|
23
|
+
],
|
|
24
|
+
element: null,
|
|
25
|
+
eventListeners: {},
|
|
26
|
+
parentItem: {},
|
|
27
|
+
tagName: 'div'
|
|
28
|
+
}
|
|
29
|
+
]
|
|
30
|
+
|
|
31
|
+
module.exports = domItem
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
const domItem = require('./domItem')
|
|
2
|
+
|
|
3
|
+
describe('domItem', () => {
|
|
4
|
+
test('has sample domItem object', () => {
|
|
5
|
+
expect(domItem[0]).toHaveProperty('attributes')
|
|
6
|
+
expect(domItem[0]).toHaveProperty('children')
|
|
7
|
+
expect(domItem[0]).toHaveProperty('element')
|
|
8
|
+
expect(domItem[0]).toHaveProperty('eventListeners')
|
|
9
|
+
expect(domItem[0]).toHaveProperty('parentItem')
|
|
10
|
+
expect(domItem[0]).toHaveProperty('tagName')
|
|
11
|
+
})
|
|
12
|
+
})
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sample of jsonDom object containing empty nested array and objects
|
|
3
|
+
* @memberOf module:testHelpers
|
|
4
|
+
* @type {Object.<string, string|number|Array|Object>}
|
|
5
|
+
*/
|
|
6
|
+
const jsonDom = {
|
|
7
|
+
tagName: 'div',
|
|
8
|
+
attributes: { style: {}, className: 'column' },
|
|
9
|
+
element: null,
|
|
10
|
+
eventListeners: {},
|
|
11
|
+
parentItem: {},
|
|
12
|
+
children: [],
|
|
13
|
+
axis: 'x'
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
module.exports = jsonDom
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
const jsonDom = require('./jsonDom')
|
|
2
|
+
|
|
3
|
+
describe('jsonDom', () => {
|
|
4
|
+
test('has sample jsonDom object', () => {
|
|
5
|
+
expect(jsonDom).toHaveProperty('attributes')
|
|
6
|
+
expect(jsonDom).toHaveProperty('children')
|
|
7
|
+
expect(jsonDom).toHaveProperty('element')
|
|
8
|
+
expect(jsonDom).toHaveProperty('eventListeners')
|
|
9
|
+
expect(jsonDom).toHaveProperty('parentItem')
|
|
10
|
+
expect(jsonDom).toHaveProperty('tagName')
|
|
11
|
+
})
|
|
12
|
+
})
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sample LinkedList for testing circular references.
|
|
3
|
+
* @memberOf module:testHelpers
|
|
4
|
+
* @type {Object.<string, string|Object>}
|
|
5
|
+
*/
|
|
6
|
+
const linkedList = { name: 'one', prev: null, next: null }
|
|
7
|
+
linkedList.next = { name: 'two', prev: linkedList, next: null }
|
|
8
|
+
linkedList.next.next = { name: 'three', prev: linkedList.next, next: null }
|
|
9
|
+
|
|
10
|
+
module.exports = linkedList
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
const linkedList = require('./linkedList')
|
|
2
|
+
|
|
3
|
+
describe('linkedList', () => {
|
|
4
|
+
test('has sample linkedList object', () => {
|
|
5
|
+
expect(linkedList.name).toBe('one')
|
|
6
|
+
expect(linkedList).toHaveProperty('prev')
|
|
7
|
+
expect(linkedList.prev).toBeNull()
|
|
8
|
+
|
|
9
|
+
expect(linkedList).toHaveProperty('next')
|
|
10
|
+
expect(linkedList.next.name).toBe('two')
|
|
11
|
+
expect(linkedList).toHaveProperty('next.prev')
|
|
12
|
+
expect(linkedList.next.prev).toBe(linkedList)
|
|
13
|
+
|
|
14
|
+
expect(linkedList).toHaveProperty('next.next')
|
|
15
|
+
expect(linkedList.next.next.name).toBe('three')
|
|
16
|
+
expect(linkedList).toHaveProperty('next.prev')
|
|
17
|
+
expect(linkedList.next.next.prev).toBe(linkedList.next)
|
|
18
|
+
|
|
19
|
+
expect(linkedList).toHaveProperty('next.next.next')
|
|
20
|
+
expect(linkedList.next.next.next).toBeNull()
|
|
21
|
+
})
|
|
22
|
+
})
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Log out an object in a nicely formatted way.
|
|
3
|
+
* @function
|
|
4
|
+
* @memberOf module:testHelpers
|
|
5
|
+
* @param {Object} object
|
|
6
|
+
* @param {string} [label=logging]
|
|
7
|
+
* @param {string} [outputType=log]
|
|
8
|
+
* @returns {string|undefined}
|
|
9
|
+
*/
|
|
10
|
+
const logObject = (object, label = 'logging', outputType = 'log') => {
|
|
11
|
+
const logger = outputType === 'string' ? (label, object) => `'${label}' | ` + JSON.stringify(object) : console[outputType]
|
|
12
|
+
if (typeof require === 'undefined' || outputType === 'string') {
|
|
13
|
+
return logger(label, object)
|
|
14
|
+
}
|
|
15
|
+
return logger(label, require('util').inspect(object, false, null, true))
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
module.exports = logObject
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
const logObject = require('./logObject')
|
|
2
|
+
const util = require('util')
|
|
3
|
+
|
|
4
|
+
describe('logObject', () => {
|
|
5
|
+
test('can nicely output objects', () => {
|
|
6
|
+
const logSpy = jest.spyOn(console, 'log').mockImplementation(jest.fn())
|
|
7
|
+
const inspectSpy = jest.spyOn(util, 'inspect')
|
|
8
|
+
const someObject = { one: 1, two: 2, three: 3 }
|
|
9
|
+
logObject(someObject, 'someObject')
|
|
10
|
+
expect(inspectSpy).toHaveBeenCalledWith(someObject, false, null, true)
|
|
11
|
+
expect(logSpy).toHaveBeenCalledWith('someObject', util.inspect(someObject, false, null, true))
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
test('output to string when that argument is provided', () => {
|
|
15
|
+
const someObject = { one: 1, two: 2, three: 3 }
|
|
16
|
+
const label = 'someObject'
|
|
17
|
+
const result = logObject(someObject, label, 'string')
|
|
18
|
+
expect(result).toEqual(`'${label}' | ` + JSON.stringify(someObject))
|
|
19
|
+
})
|
|
20
|
+
})
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sample of object containing multiple references.
|
|
3
|
+
* @memberOf module:testHelpers
|
|
4
|
+
* @type {Object.<string, string|number|Object>}
|
|
5
|
+
*/
|
|
6
|
+
const multiReferenceObject = {
|
|
7
|
+
object1: {
|
|
8
|
+
name: 'someName'
|
|
9
|
+
},
|
|
10
|
+
object2: {
|
|
11
|
+
age: 12
|
|
12
|
+
},
|
|
13
|
+
array1: [
|
|
14
|
+
'someString',
|
|
15
|
+
'anotherString'
|
|
16
|
+
],
|
|
17
|
+
array2: [
|
|
18
|
+
89,
|
|
19
|
+
32
|
|
20
|
+
],
|
|
21
|
+
title: 'Some Title',
|
|
22
|
+
item: 45
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
module.exports = multiReferenceObject
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
const multiReferenceObject = require('./multiReferenceObject')
|
|
2
|
+
|
|
3
|
+
describe('multiReferenceObject', () => {
|
|
4
|
+
test('has sample multiReferenceObject object', () => {
|
|
5
|
+
expect(multiReferenceObject).toHaveProperty('object1.name')
|
|
6
|
+
expect(multiReferenceObject).toHaveProperty('object2.age')
|
|
7
|
+
expect(multiReferenceObject).toHaveProperty('array1.0')
|
|
8
|
+
expect(multiReferenceObject).toHaveProperty('array1.1')
|
|
9
|
+
expect(multiReferenceObject).toHaveProperty('array2.0')
|
|
10
|
+
expect(multiReferenceObject).toHaveProperty('array2.1')
|
|
11
|
+
expect(multiReferenceObject).toHaveProperty('title')
|
|
12
|
+
expect(multiReferenceObject).toHaveProperty('item')
|
|
13
|
+
})
|
|
14
|
+
})
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sample NodeTree for testing circular references and arrays.
|
|
3
|
+
* @memberOf module:testHelpers
|
|
4
|
+
* @type {Object.<string, string|Object|Array>}
|
|
5
|
+
*/
|
|
6
|
+
const nodeTree = { name: 'one', parent: null, children: [] }
|
|
7
|
+
nodeTree.children[0] = { name: 'child one', parent: nodeTree, children: [] }
|
|
8
|
+
nodeTree.children[1] = { name: 'child two', parent: nodeTree, children: [] }
|
|
9
|
+
nodeTree.children[0].children[0] = { name: 'grandchild one', parent: nodeTree.children[0], children: [] }
|
|
10
|
+
|
|
11
|
+
module.exports = nodeTree
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import nodeTree from './nodeTree'
|
|
2
|
+
|
|
3
|
+
describe('nodeTree', () => {
|
|
4
|
+
test('has sample nodeTree object', () => {
|
|
5
|
+
expect(nodeTree.name).toBe('one')
|
|
6
|
+
expect(nodeTree.parent).toBeNull()
|
|
7
|
+
expect(nodeTree.children.length).toBe(2)
|
|
8
|
+
expect(nodeTree.children[0].name).toBe('child one')
|
|
9
|
+
expect(nodeTree.children[0].parent).toBe(nodeTree)
|
|
10
|
+
expect(nodeTree.children[0].children.length).toBe(1)
|
|
11
|
+
expect(nodeTree.children[0].children[0].name).toBe('grandchild one')
|
|
12
|
+
expect(nodeTree.children[0].children[0].parent).toBe(nodeTree.children[0])
|
|
13
|
+
expect(nodeTree.children[0].children[0].children.length).toBe(0)
|
|
14
|
+
expect(nodeTree.children[1].name).toBe('child two')
|
|
15
|
+
expect(nodeTree.children[1].parent).toBe(nodeTree)
|
|
16
|
+
expect(nodeTree.children[1].children.length).toBe(0)
|
|
17
|
+
})
|
|
18
|
+
})
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
const fs = require('fs')
|
|
2
|
+
const del = require('del')
|
|
3
|
+
// Import the configurations and override some of them in order to direct to the temp directory.
|
|
4
|
+
const gulpConfig = require('../../gulp.config.js')
|
|
5
|
+
|
|
6
|
+
let tempDir = 'test-temp/'
|
|
7
|
+
let srcPath = `${tempDir}src`
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Update the gulp configurations with the test data. Set the test directory where temp files will be created for testing.
|
|
11
|
+
* @function
|
|
12
|
+
* @memberOf module:testHelpers
|
|
13
|
+
* @param {string} testDir
|
|
14
|
+
*/
|
|
15
|
+
const setDefaults = (testDir = 'test-temp') => {
|
|
16
|
+
tempDir = `${testDir}/`
|
|
17
|
+
srcPath = `${tempDir}src`
|
|
18
|
+
gulpConfig.set('browserPath', `${tempDir}browser`)
|
|
19
|
+
gulpConfig.set('distMain', `${tempDir}dist/main`)
|
|
20
|
+
gulpConfig.set('distPath', `${tempDir}dist`)
|
|
21
|
+
gulpConfig.set('distSearch', `${tempDir}dist/**/*.js`)
|
|
22
|
+
gulpConfig.set('readmeTemplate', `${tempDir}MAIN.md`)
|
|
23
|
+
gulpConfig.set('readmePath', tempDir)
|
|
24
|
+
gulpConfig.set('rootPath', tempDir)
|
|
25
|
+
gulpConfig.set('srcPath', srcPath)
|
|
26
|
+
gulpConfig.set('srcSearch', `${tempDir}src/**/!(*.test).js`)
|
|
27
|
+
gulpConfig.set('tsSearch', `${tempDir}src/**/*.ts`)
|
|
28
|
+
gulpConfig.set('watchSearch', `${tempDir}src/**/*.js`)
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
exports.setDefaults = setDefaults
|
|
32
|
+
|
|
33
|
+
exports.gulpConfig = gulpConfig
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Ensure that the del has completed, recursively attempt to delete and recreate
|
|
37
|
+
* @function
|
|
38
|
+
* @memberOf module:testHelpers
|
|
39
|
+
* @param {boolean} [exists=true]
|
|
40
|
+
* @returns {Promise<*|void>}
|
|
41
|
+
*/
|
|
42
|
+
const createTempDir = async (exists = true) => {
|
|
43
|
+
if (exists) {
|
|
44
|
+
return del(tempDir)
|
|
45
|
+
.then(() => createTempDir(fs.existsSync(tempDir)))
|
|
46
|
+
}
|
|
47
|
+
await fs.mkdirSync(tempDir)
|
|
48
|
+
return fs.mkdirSync(srcPath)
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
exports.createTempDir = createTempDir
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* In the Jest.beforeEach function call this one to set up the temp directory.
|
|
55
|
+
* @function
|
|
56
|
+
* @memberOf module:testHelpers
|
|
57
|
+
* @returns {Promise<*|void>}
|
|
58
|
+
*/
|
|
59
|
+
exports.beforeEach = () => createTempDir()
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* In the Jest.afterEach function call this one to clean up and remove the temp directory.
|
|
63
|
+
* @function
|
|
64
|
+
* @memberOf module:testHelpers
|
|
65
|
+
* @returns {Promise<*>}
|
|
66
|
+
*/
|
|
67
|
+
exports.afterEach = async () => await del(tempDir)
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { afterEach, createTempDir, gulpConfig, setDefaults } from './setUp'
|
|
2
|
+
import fs from 'fs'
|
|
3
|
+
|
|
4
|
+
setDefaults()
|
|
5
|
+
|
|
6
|
+
describe('setUp', () => {
|
|
7
|
+
test('able to create the test-temp/src directory', async () => {
|
|
8
|
+
expect(fs.existsSync(gulpConfig.get('srcPath'))).toBeFalsy()
|
|
9
|
+
await createTempDir()
|
|
10
|
+
expect(fs.existsSync(gulpConfig.get('srcPath'))).toBeTruthy()
|
|
11
|
+
})
|
|
12
|
+
|
|
13
|
+
test('able to delete the test-temp/src directory', async () => {
|
|
14
|
+
expect(fs.existsSync(gulpConfig.get('srcPath'))).toBeTruthy()
|
|
15
|
+
await afterEach()
|
|
16
|
+
expect(fs.existsSync(gulpConfig.get('srcPath'))).toBeFalsy()
|
|
17
|
+
})
|
|
18
|
+
})
|
package/functions/testFull.js
CHANGED
|
@@ -1,10 +1,20 @@
|
|
|
1
|
-
const gulpConfig = require('../gulp.config.js')
|
|
2
|
-
const { runCLI
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Run all tests with jest.
|
|
6
|
-
* @
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
const gulpConfig = require('../gulp.config.js')
|
|
2
|
+
const { runCLI } = require('jest')
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Run all tests with jest.
|
|
6
|
+
* @function
|
|
7
|
+
* @memberOf module:js-build-tools
|
|
8
|
+
* @param {function} [done=null]
|
|
9
|
+
* @param {Array.<string>|string} [testPath='path/config/test/files']
|
|
10
|
+
* @returns {Promise<*>}
|
|
11
|
+
*/
|
|
12
|
+
const testFull = (done = null, testPath = gulpConfig.get('testPath')) => {
|
|
13
|
+
if (!Array.isArray(testPath)) {
|
|
14
|
+
// The testPath must be an array of strings
|
|
15
|
+
testPath = [testPath]
|
|
16
|
+
}
|
|
17
|
+
return runCLI(gulpConfig.get('testOptions'), testPath)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
module.exports = testFull
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
const { setUp } = require('./testHelpers')
|
|
2
|
+
const gulpConfig = setUp.gulpConfig
|
|
3
|
+
const { runCLI } = require('jest')
|
|
4
|
+
const testFull = require('./testFull')
|
|
5
|
+
|
|
6
|
+
jest.mock('jest', () => ({
|
|
7
|
+
'runCLI': jest.fn(() => Promise.resolve(true))
|
|
8
|
+
}))
|
|
9
|
+
|
|
10
|
+
describe('testFull', () => {
|
|
11
|
+
test('runs the Jest CLI with the configured options', () => {
|
|
12
|
+
expect.assertions(1)
|
|
13
|
+
testFull()
|
|
14
|
+
expect(runCLI).toHaveBeenCalledWith(gulpConfig.get('testOptions'), [gulpConfig.get('testPath')])
|
|
15
|
+
})
|
|
16
|
+
})
|
package/functions/testHelpers.js
CHANGED
|
@@ -1,142 +1,32 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
* @
|
|
4
|
-
* @
|
|
2
|
+
* An assortment of objects that can be used in tests and some functions to help debug and write tests.
|
|
3
|
+
* @file
|
|
4
|
+
* @author Joshua Heagle <joshuaheagle@gmail.com>
|
|
5
|
+
* @version 2.0.0
|
|
6
|
+
* @module testHelpers
|
|
7
|
+
* @memberOf module:js-build-tools
|
|
5
8
|
*/
|
|
6
|
-
export const logObject = (object, label = 'logging') => {
|
|
7
|
-
if (typeof require === 'undefined') {
|
|
8
|
-
console.log(label, object)
|
|
9
|
-
return
|
|
10
|
-
}
|
|
11
|
-
console.log(label, require('util').inspect(object, false, null, true))
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Multilayered node tree-like structure with parent references
|
|
16
|
-
* @type {Object.<string, string|Object|Array>}
|
|
17
|
-
*/
|
|
18
|
-
export const circularObject = { name: 'root', parent: {}, body: {}, head: {}, children: [] }
|
|
19
|
-
circularObject.children = [
|
|
20
|
-
{ name: 'body', parent: {}, children: [] },
|
|
21
|
-
{ name: 'head', parent: {}, children: [] }
|
|
22
|
-
]
|
|
23
|
-
circularObject.body = circularObject.children[0]
|
|
24
|
-
circularObject.head = circularObject.children[1]
|
|
25
|
-
circularObject.body.parent = circularObject
|
|
26
|
-
circularObject.head.parent = circularObject
|
|
27
|
-
circularObject.body.children = [
|
|
28
|
-
{ name: 'body child one', parent: {}, children: [] },
|
|
29
|
-
{ name: 'body child two', parent: {}, children: [] }
|
|
30
|
-
]
|
|
31
|
-
circularObject.body.children[0].parent = circularObject.body
|
|
32
|
-
circularObject.body.children[1].parent = circularObject.body
|
|
33
|
-
circularObject.head.children = [
|
|
34
|
-
{ name: 'head child one', parent: {}, children: [] },
|
|
35
|
-
{ name: 'head child two', parent: {}, children: [] }
|
|
36
|
-
]
|
|
37
|
-
circularObject.head.children[0].parent = circularObject.head
|
|
38
|
-
circularObject.head.children[1].parent = circularObject.head
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* Sample object with deep references.
|
|
42
|
-
* @type {Object.<string, string|number|Object>}
|
|
43
|
-
*/
|
|
44
|
-
export const deepReferenceObject = {
|
|
45
|
-
object1: {
|
|
46
|
-
name: 'someName',
|
|
47
|
-
object2: {
|
|
48
|
-
age: 12,
|
|
49
|
-
array1: [
|
|
50
|
-
'someString',
|
|
51
|
-
'anotherString'
|
|
52
|
-
]
|
|
53
|
-
},
|
|
54
|
-
array2: [
|
|
55
|
-
89,
|
|
56
|
-
32
|
|
57
|
-
]
|
|
58
|
-
},
|
|
59
|
-
title: 'Some Title',
|
|
60
|
-
item: 45
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* Sample LinkedList for testing circular references.
|
|
65
|
-
* @type {Object.<string, string|Object>}
|
|
66
|
-
*/
|
|
67
|
-
export const linkedList = { name: 'one', prev: null, next: null }
|
|
68
|
-
linkedList.next = { name: 'two', prev: linkedList, next: null }
|
|
69
|
-
linkedList.next.next = { name: 'three', prev: linkedList.next, next: null }
|
|
70
9
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
axis: 'x'
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
/**
|
|
85
|
-
* Sample of domItem child with nested child and optional details
|
|
86
|
-
*/
|
|
87
|
-
export const domItem = [
|
|
88
|
-
{
|
|
89
|
-
attributes: { className: 'row', style: {} },
|
|
90
|
-
axis: 'y',
|
|
91
|
-
children: [
|
|
92
|
-
{
|
|
93
|
-
attributes: { style: {} },
|
|
94
|
-
axis: 'x',
|
|
95
|
-
children: [],
|
|
96
|
-
element: {},
|
|
97
|
-
eventListeners: {},
|
|
98
|
-
hasShip: false,
|
|
99
|
-
isHit: false,
|
|
100
|
-
parentItem: {},
|
|
101
|
-
point: {},
|
|
102
|
-
tagName: 'div'
|
|
103
|
-
}
|
|
104
|
-
],
|
|
105
|
-
element: null,
|
|
106
|
-
eventListeners: {},
|
|
107
|
-
parentItem: {},
|
|
108
|
-
tagName: 'div'
|
|
109
|
-
}
|
|
110
|
-
]
|
|
10
|
+
const circularObject = require('./test-helpers/circularObject')
|
|
11
|
+
const countMatches = require('./test-helpers/countMatches')
|
|
12
|
+
const deepReferenceObject = require('./test-helpers/deepReferenceObject')
|
|
13
|
+
const domItem = require('./test-helpers/domItem')
|
|
14
|
+
const jsonDom = require('./test-helpers/jsonDom')
|
|
15
|
+
const linkedList = require('./test-helpers/linkedList')
|
|
16
|
+
const logObject = require('./test-helpers/logObject')
|
|
17
|
+
const multiReferenceObject = require('./test-helpers/multiReferenceObject')
|
|
18
|
+
const nodeTree = require('./test-helpers/nodeTree')
|
|
19
|
+
const setUp = require('./test-helpers/setUp')
|
|
111
20
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
array1: [
|
|
124
|
-
'someString',
|
|
125
|
-
'anotherString'
|
|
126
|
-
],
|
|
127
|
-
array2: [
|
|
128
|
-
89,
|
|
129
|
-
32
|
|
130
|
-
],
|
|
131
|
-
title: 'Some Title',
|
|
132
|
-
item: 45
|
|
21
|
+
module.exports = {
|
|
22
|
+
circularObject,
|
|
23
|
+
countMatches,
|
|
24
|
+
deepReferenceObject,
|
|
25
|
+
domItem,
|
|
26
|
+
jsonDom,
|
|
27
|
+
linkedList,
|
|
28
|
+
logObject,
|
|
29
|
+
multiReferenceObject,
|
|
30
|
+
nodeTree,
|
|
31
|
+
setUp,
|
|
133
32
|
}
|
|
134
|
-
|
|
135
|
-
/**
|
|
136
|
-
* Sample NodeTree for testing circular references and arrays.
|
|
137
|
-
* @type {Object.<string, string|Object|Array>}
|
|
138
|
-
*/
|
|
139
|
-
export const nodeTree = { name: 'one', parent: null, children: [] }
|
|
140
|
-
nodeTree.children[0] = { name: 'child one', parent: nodeTree, children: [] }
|
|
141
|
-
nodeTree.children[1] = { name: 'child two', parent: nodeTree, children: [] }
|
|
142
|
-
nodeTree.children[0].children[0] = { name: 'grandchild one', parent: nodeTree.children[0], children: [] }
|
|
@@ -1,100 +1,7 @@
|
|
|
1
|
-
const
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
multiReferenceObject,
|
|
9
|
-
nodeTree
|
|
10
|
-
} = require('./testHelpers.js')
|
|
11
|
-
const util = require('util')
|
|
12
|
-
|
|
13
|
-
describe('testHelpers', () => {
|
|
14
|
-
test('can nicely output objects with logObject', () => {
|
|
15
|
-
const logSpy = jest.spyOn(console, 'log')
|
|
16
|
-
const inspectSpy = jest.spyOn(util, 'inspect')
|
|
17
|
-
const someObject = { one: 1, two: 2, three: 3 }
|
|
18
|
-
logObject(someObject, 'someObject')
|
|
19
|
-
expect(inspectSpy).toHaveBeenCalledWith(someObject, false, null, true)
|
|
20
|
-
expect(logSpy).toHaveBeenCalledWith('someObject', util.inspect(someObject, false, null, true))
|
|
21
|
-
})
|
|
22
|
-
|
|
23
|
-
test('has sample circular object', () => {
|
|
24
|
-
expect(circularObject.body.parent).toBe(circularObject)
|
|
25
|
-
expect(circularObject.body.children[0].parent).toBe(circularObject.body)
|
|
26
|
-
expect(circularObject.body.children[1].parent).toBe(circularObject.body)
|
|
27
|
-
expect(circularObject.children[0]).toBe(circularObject.body)
|
|
28
|
-
expect(circularObject.head.parent).toBe(circularObject)
|
|
29
|
-
expect(circularObject.head.children[0].parent).toBe(circularObject.head)
|
|
30
|
-
expect(circularObject.head.children[1].parent).toBe(circularObject.head)
|
|
31
|
-
expect(circularObject.children[1]).toBe(circularObject.head)
|
|
32
|
-
})
|
|
33
|
-
|
|
34
|
-
test('has sample deep reference object', () => {
|
|
35
|
-
expect(deepReferenceObject).toHaveProperty('object1.object2.array1')
|
|
36
|
-
})
|
|
37
|
-
|
|
38
|
-
test('has sample domItem object', () => {
|
|
39
|
-
expect(domItem[0]).toHaveProperty('attributes')
|
|
40
|
-
expect(domItem[0]).toHaveProperty('children')
|
|
41
|
-
expect(domItem[0]).toHaveProperty('element')
|
|
42
|
-
expect(domItem[0]).toHaveProperty('eventListeners')
|
|
43
|
-
expect(domItem[0]).toHaveProperty('parentItem')
|
|
44
|
-
expect(domItem[0]).toHaveProperty('tagName')
|
|
45
|
-
})
|
|
46
|
-
|
|
47
|
-
test('has sample jsonDom object', () => {
|
|
48
|
-
expect(jsonDom).toHaveProperty('attributes')
|
|
49
|
-
expect(jsonDom).toHaveProperty('children')
|
|
50
|
-
expect(jsonDom).toHaveProperty('element')
|
|
51
|
-
expect(jsonDom).toHaveProperty('eventListeners')
|
|
52
|
-
expect(jsonDom).toHaveProperty('parentItem')
|
|
53
|
-
expect(jsonDom).toHaveProperty('tagName')
|
|
54
|
-
})
|
|
55
|
-
|
|
56
|
-
test('has sample linkedList object', () => {
|
|
57
|
-
expect(linkedList.name).toBe('one')
|
|
58
|
-
expect(linkedList).toHaveProperty('prev')
|
|
59
|
-
expect(linkedList.prev).toBeNull()
|
|
60
|
-
|
|
61
|
-
expect(linkedList).toHaveProperty('next')
|
|
62
|
-
expect(linkedList.next.name).toBe('two')
|
|
63
|
-
expect(linkedList).toHaveProperty('next.prev')
|
|
64
|
-
expect(linkedList.next.prev).toBe(linkedList)
|
|
65
|
-
|
|
66
|
-
expect(linkedList).toHaveProperty('next.next')
|
|
67
|
-
expect(linkedList.next.next.name).toBe('three')
|
|
68
|
-
expect(linkedList).toHaveProperty('next.prev')
|
|
69
|
-
expect(linkedList.next.next.prev).toBe(linkedList.next)
|
|
70
|
-
|
|
71
|
-
expect(linkedList).toHaveProperty('next.next.next')
|
|
72
|
-
expect(linkedList.next.next.next).toBeNull()
|
|
73
|
-
})
|
|
74
|
-
|
|
75
|
-
test('has sample multiReferenceObject object', () => {
|
|
76
|
-
expect(multiReferenceObject).toHaveProperty('object1.name')
|
|
77
|
-
expect(multiReferenceObject).toHaveProperty('object2.age')
|
|
78
|
-
expect(multiReferenceObject).toHaveProperty('array1.0')
|
|
79
|
-
expect(multiReferenceObject).toHaveProperty('array1.1')
|
|
80
|
-
expect(multiReferenceObject).toHaveProperty('array2.0')
|
|
81
|
-
expect(multiReferenceObject).toHaveProperty('array2.1')
|
|
82
|
-
expect(multiReferenceObject).toHaveProperty('title')
|
|
83
|
-
expect(multiReferenceObject).toHaveProperty('item')
|
|
84
|
-
})
|
|
85
|
-
|
|
86
|
-
test('has sample nodeTree object', () => {
|
|
87
|
-
expect(nodeTree.name).toBe('one')
|
|
88
|
-
expect(nodeTree.parent).toBeNull()
|
|
89
|
-
expect(nodeTree.children.length).toBe(2)
|
|
90
|
-
expect(nodeTree.children[0].name).toBe('child one')
|
|
91
|
-
expect(nodeTree.children[0].parent).toBe(nodeTree)
|
|
92
|
-
expect(nodeTree.children[0].children.length).toBe(1)
|
|
93
|
-
expect(nodeTree.children[0].children[0].name).toBe('grandchild one')
|
|
94
|
-
expect(nodeTree.children[0].children[0].parent).toBe(nodeTree.children[0])
|
|
95
|
-
expect(nodeTree.children[0].children[0].children.length).toBe(0)
|
|
96
|
-
expect(nodeTree.children[1].name).toBe('child two')
|
|
97
|
-
expect(nodeTree.children[1].parent).toBe(nodeTree)
|
|
98
|
-
expect(nodeTree.children[1].children.length).toBe(0)
|
|
99
|
-
})
|
|
100
|
-
})
|
|
1
|
+
const testHelpers = require('./testHelpers')
|
|
2
|
+
|
|
3
|
+
describe('testHelpers', () => {
|
|
4
|
+
test('is object with all helper exports', () => {
|
|
5
|
+
expect(Object.keys(testHelpers).length).toBe(10)
|
|
6
|
+
})
|
|
7
|
+
})
|