test-filesystem 1.0.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/LICENSE +674 -0
- package/README.md +163 -0
- package/browser/test-fs.js +2856 -0
- package/browser/test-fs.min.js +1 -0
- package/dist/cjs/functions/circularObject.js +54 -0
- package/dist/cjs/functions/circularObject.min.js +1 -0
- package/dist/cjs/functions/countMatches.js +17 -0
- package/dist/cjs/functions/countMatches.min.js +1 -0
- package/dist/cjs/functions/deepReferenceObject.js +24 -0
- package/dist/cjs/functions/deepReferenceObject.min.js +1 -0
- package/dist/cjs/functions/domItem.js +37 -0
- package/dist/cjs/functions/domItem.min.js +1 -0
- package/dist/cjs/functions/jsonDom.js +24 -0
- package/dist/cjs/functions/jsonDom.min.js +1 -0
- package/dist/cjs/functions/linkedList.js +27 -0
- package/dist/cjs/functions/linkedList.min.js +1 -0
- package/dist/cjs/functions/logObject.js +24 -0
- package/dist/cjs/functions/logObject.min.js +1 -0
- package/dist/cjs/functions/multiReferenceObject.js +24 -0
- package/dist/cjs/functions/multiReferenceObject.min.js +1 -0
- package/dist/cjs/functions/nodeTree.js +32 -0
- package/dist/cjs/functions/nodeTree.min.js +1 -0
- package/dist/cjs/functions/removeDirectory.js +19 -0
- package/dist/cjs/functions/removeDirectory.min.js +1 -0
- package/dist/cjs/functions/setUp.js +87 -0
- package/dist/cjs/functions/setUp.min.js +1 -0
- package/dist/cjs/main.js +58 -0
- package/dist/cjs/main.min.js +1 -0
- package/dist/mjs/functions/circularObject.d.ts +14 -0
- package/dist/mjs/functions/circularObject.min.mjs +1 -0
- package/dist/mjs/functions/circularObject.mjs +33 -0
- package/dist/mjs/functions/countMatches.d.ts +10 -0
- package/dist/mjs/functions/countMatches.min.mjs +1 -0
- package/dist/mjs/functions/countMatches.mjs +10 -0
- package/dist/mjs/functions/deepReferenceObject.d.ts +18 -0
- package/dist/mjs/functions/deepReferenceObject.min.mjs +1 -0
- package/dist/mjs/functions/deepReferenceObject.mjs +24 -0
- package/dist/mjs/functions/domItem.d.ts +24 -0
- package/dist/mjs/functions/domItem.min.mjs +1 -0
- package/dist/mjs/functions/domItem.mjs +30 -0
- package/dist/mjs/functions/jsonDom.d.ts +8 -0
- package/dist/mjs/functions/jsonDom.min.mjs +1 -0
- package/dist/mjs/functions/jsonDom.mjs +15 -0
- package/dist/mjs/functions/linkedList.d.ts +12 -0
- package/dist/mjs/functions/linkedList.min.mjs +1 -0
- package/dist/mjs/functions/linkedList.mjs +9 -0
- package/dist/mjs/functions/logObject.d.ts +11 -0
- package/dist/mjs/functions/logObject.min.mjs +1 -0
- package/dist/mjs/functions/logObject.mjs +17 -0
- package/dist/mjs/functions/multiReferenceObject.d.ts +18 -0
- package/dist/mjs/functions/multiReferenceObject.min.mjs +1 -0
- package/dist/mjs/functions/multiReferenceObject.mjs +24 -0
- package/dist/mjs/functions/nodeTree.d.ts +12 -0
- package/dist/mjs/functions/nodeTree.min.mjs +1 -0
- package/dist/mjs/functions/nodeTree.mjs +10 -0
- package/dist/mjs/functions/removeDirectory.d.ts +9 -0
- package/dist/mjs/functions/removeDirectory.min.mjs +1 -0
- package/dist/mjs/functions/removeDirectory.mjs +12 -0
- package/dist/mjs/functions/setUp.d.ts +30 -0
- package/dist/mjs/functions/setUp.min.mjs +1 -0
- package/dist/mjs/functions/setUp.mjs +56 -0
- package/dist/mjs/main.d.ts +93 -0
- package/dist/mjs/main.min.mjs +1 -0
- package/dist/mjs/main.mjs +50 -0
- package/gulpfile.js +221 -0
- package/package.json +58 -0
package/gulpfile.js
ADDED
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
const babel = require('gulp-babel')
|
|
2
|
+
const browserify = require('browserify')
|
|
3
|
+
const { dest, parallel, series, src } = require('gulp')
|
|
4
|
+
const { access, appendFileSync, constants, rm } = require('fs')
|
|
5
|
+
const jsdoc2md = require('jsdoc-to-markdown')
|
|
6
|
+
const { globSync } = require('glob')
|
|
7
|
+
const merge = require('merge2') // Requires separate installation
|
|
8
|
+
const rename = require('gulp-rename')
|
|
9
|
+
const { runCLI } = require('jest')
|
|
10
|
+
const source = require('vinyl-source-stream')
|
|
11
|
+
const standard = require('gulp-standard')
|
|
12
|
+
const ts = require('gulp-typescript')
|
|
13
|
+
const { default: uglify } = require('gulp-uglify-es')
|
|
14
|
+
|
|
15
|
+
const browserName = 'test-fs'
|
|
16
|
+
const browserPath = 'browser'
|
|
17
|
+
const cleanFolders = ['dist', 'browser']
|
|
18
|
+
const distSearch = 'dist/**/*js'
|
|
19
|
+
const distMain = 'dist/cjs/main'
|
|
20
|
+
const distPath = 'dist'
|
|
21
|
+
const srcSearch = 'src/**/*.ts'
|
|
22
|
+
const readmeTemplate = 'MAIN.md'
|
|
23
|
+
const readmeFile = 'README.md'
|
|
24
|
+
const readmePath = './'
|
|
25
|
+
const readmeSearch = 'dist/cjs/**/*.js'
|
|
26
|
+
const readmeOptions = 'utf8'
|
|
27
|
+
const testPath = ['src']
|
|
28
|
+
const testOptions = {
|
|
29
|
+
clearCache: false,
|
|
30
|
+
debug: false,
|
|
31
|
+
ignoreProjects: false,
|
|
32
|
+
json: false,
|
|
33
|
+
selectProjects: false,
|
|
34
|
+
showConfig: false,
|
|
35
|
+
useStderr: false,
|
|
36
|
+
watch: false,
|
|
37
|
+
watchAll: false,
|
|
38
|
+
}
|
|
39
|
+
const tsConfig = './tsconfig.json'
|
|
40
|
+
const cjsPath = `${distPath}/cjs`
|
|
41
|
+
const tsPath = `${distPath}/mjs`
|
|
42
|
+
const tsSearch = `${distPath}/mjs/**/*.mjs`
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Return a promise to be completed once the specified directory is deleted.
|
|
46
|
+
* @function
|
|
47
|
+
* @memberOf module:test-fs
|
|
48
|
+
* @param {string} dirPath
|
|
49
|
+
* @returns {Promise<*>}
|
|
50
|
+
*/
|
|
51
|
+
const removeDirectory = (dirPath) => new Promise(
|
|
52
|
+
(resolve, reject) => access(
|
|
53
|
+
dirPath,
|
|
54
|
+
constants.F_OK,
|
|
55
|
+
(removed) => removed
|
|
56
|
+
? resolve(dirPath)
|
|
57
|
+
: rm(
|
|
58
|
+
dirPath,
|
|
59
|
+
{ recursive: true },
|
|
60
|
+
(error) => error ? reject(error) : resolve(dirPath)
|
|
61
|
+
)
|
|
62
|
+
)
|
|
63
|
+
)
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Deletes all the distribution and browser files (used before create a new build).
|
|
67
|
+
* Configure array of directories to remove with 'cleanPaths'.
|
|
68
|
+
* @function
|
|
69
|
+
* @returns {Promise<string[]> | *}
|
|
70
|
+
*/
|
|
71
|
+
const clean = () => cleanFolders.reduce(
|
|
72
|
+
(promise, path) => promise.then(() => removeDirectory(path)),
|
|
73
|
+
Promise.resolve()
|
|
74
|
+
)
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Starting at the source directory, find all the ts files and convert them into the distribution directory.
|
|
78
|
+
* @function
|
|
79
|
+
* @returns {Function}
|
|
80
|
+
* @see `https://www.typescriptlang.org/docs/handbook/gulp.html` for more info
|
|
81
|
+
*/
|
|
82
|
+
const typescript = () => {
|
|
83
|
+
const tsResult = src(srcSearch)
|
|
84
|
+
.pipe(ts({
|
|
85
|
+
declaration: true,
|
|
86
|
+
moduleResolution: 'node',
|
|
87
|
+
target: 'es6',
|
|
88
|
+
module: 'es2020'
|
|
89
|
+
}))
|
|
90
|
+
return merge([
|
|
91
|
+
tsResult.dts.pipe(dest(tsPath)),
|
|
92
|
+
tsResult.js.pipe(rename({ extname: '.mjs' })).pipe(dest(tsPath))
|
|
93
|
+
])
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* When using TypeScript, ensure that we process the ts first then run babel (dist)
|
|
98
|
+
* @function
|
|
99
|
+
* @returns {function(null=): stream.Stream}
|
|
100
|
+
*/
|
|
101
|
+
const distSeries = (done = null) => {
|
|
102
|
+
const dist = () => src(tsSearch)
|
|
103
|
+
.pipe(babel())
|
|
104
|
+
.pipe(dest(cjsPath))
|
|
105
|
+
return series(typescript, dist)(done)
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Applies Standard code style linting to distribution files.
|
|
110
|
+
* @function
|
|
111
|
+
* @returns {*}
|
|
112
|
+
*/
|
|
113
|
+
const distLint = () => src(distSearch)
|
|
114
|
+
.pipe(standard({ fix: true }))
|
|
115
|
+
.pipe(standard.reporter('default', {
|
|
116
|
+
fix: true,
|
|
117
|
+
quiet: true
|
|
118
|
+
}))
|
|
119
|
+
.pipe(dest(distPath))
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Creates minified versions of the dist files.
|
|
123
|
+
* @function
|
|
124
|
+
* @returns {*}
|
|
125
|
+
*/
|
|
126
|
+
const distMinify = () => src(distSearch)
|
|
127
|
+
.pipe(uglify())
|
|
128
|
+
.pipe(rename(path => {
|
|
129
|
+
if (path.extname) {
|
|
130
|
+
path.extname = `.min${path.extname}`
|
|
131
|
+
}
|
|
132
|
+
}))
|
|
133
|
+
.pipe(dest(distPath))
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Copy a readme template into the README.md file.
|
|
137
|
+
* @function
|
|
138
|
+
* @returns {*}
|
|
139
|
+
*/
|
|
140
|
+
const createReadme = () => src(readmeTemplate)
|
|
141
|
+
.pipe(rename(readmeFile))
|
|
142
|
+
.pipe(dest(readmePath))
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Appends all the jsdoc comments to the readme file. Assumes empty or templated file.
|
|
146
|
+
* Configure this with 'readmeSearch', 'readmePath', 'readmeFile', and 'readmeOptions'.
|
|
147
|
+
* @function
|
|
148
|
+
* @returns {string|Uint8Array}
|
|
149
|
+
*/
|
|
150
|
+
const addToReadme = () => jsdoc2md
|
|
151
|
+
.render({ files: globSync(readmeSearch) })
|
|
152
|
+
.then(
|
|
153
|
+
readme => appendFileSync(readmePath + readmeFile, readme, readmeOptions)
|
|
154
|
+
)
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Generate the readme file.
|
|
158
|
+
* @function
|
|
159
|
+
* @return {*}
|
|
160
|
+
*/
|
|
161
|
+
const buildReadme = (done = null) => series(createReadme, addToReadme)(done)
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* Starting at the distribution entry point, bundle all the files into a single file and store them in the specified output directory.
|
|
165
|
+
* @function
|
|
166
|
+
* @returns {stream.Stream}
|
|
167
|
+
*/
|
|
168
|
+
const bundle = () => browserify(distMain)
|
|
169
|
+
.bundle()
|
|
170
|
+
.pipe(source(`${browserName}.js`))
|
|
171
|
+
.pipe(dest(browserPath))
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* Applies Standard code style linting to bundled file.
|
|
175
|
+
* @function
|
|
176
|
+
* @returns {stream.Stream}
|
|
177
|
+
*/
|
|
178
|
+
const bundleLint = () => src(`${browserPath}/${browserName}.js`)
|
|
179
|
+
.pipe(standard({ fix: true }))
|
|
180
|
+
.pipe(standard.reporter('default', {
|
|
181
|
+
fix: true,
|
|
182
|
+
quiet: true
|
|
183
|
+
}))
|
|
184
|
+
.pipe(dest(browserPath))
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* Creates the minified bundle file.
|
|
188
|
+
* @function
|
|
189
|
+
* @returns {*}
|
|
190
|
+
*/
|
|
191
|
+
const bundleMinify = () => src(`${browserPath}/${browserName}.js`)
|
|
192
|
+
.pipe(uglify())
|
|
193
|
+
.pipe(rename({ extname: '.min.js' }))
|
|
194
|
+
.pipe(dest(browserPath))
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* Run all tests with jest.
|
|
198
|
+
* Configure where tests are located by using 'testPath'.
|
|
199
|
+
* @function
|
|
200
|
+
* @returns {Promise<*>}
|
|
201
|
+
*/
|
|
202
|
+
const testFull = () => runCLI(testOptions, testPath)
|
|
203
|
+
|
|
204
|
+
const build = (done = null) => parallel(
|
|
205
|
+
series(
|
|
206
|
+
clean,
|
|
207
|
+
distSeries,
|
|
208
|
+
parallel(distLint, distMinify),
|
|
209
|
+
buildReadme,
|
|
210
|
+
bundle,
|
|
211
|
+
parallel(bundleLint, bundleMinify)
|
|
212
|
+
),
|
|
213
|
+
testFull
|
|
214
|
+
)(done)
|
|
215
|
+
|
|
216
|
+
exports.bundle = bundle
|
|
217
|
+
exports.dist = distSeries
|
|
218
|
+
exports.build = build
|
|
219
|
+
exports.readme = buildReadme
|
|
220
|
+
exports.testFull = testFull
|
|
221
|
+
exports.typescript = typescript
|
package/package.json
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "test-filesystem",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Set up and tear down a temp directory for running filesystem tests.",
|
|
5
|
+
"main": "dist/cjs/main.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"build": "gulp build",
|
|
8
|
+
"htmldocs": "jsdoc -R MAIN.md -c ./.jsdoc.conf.js -d docs",
|
|
9
|
+
"readme": "gulp readme",
|
|
10
|
+
"test": "gulp testFull"
|
|
11
|
+
},
|
|
12
|
+
"repository": {
|
|
13
|
+
"type": "git",
|
|
14
|
+
"url": "git+https://github.com/jheagle/test-fs.git"
|
|
15
|
+
},
|
|
16
|
+
"keywords": [
|
|
17
|
+
"jest",
|
|
18
|
+
"testing",
|
|
19
|
+
"filesystem",
|
|
20
|
+
"fs",
|
|
21
|
+
"helpers"
|
|
22
|
+
],
|
|
23
|
+
"author": "Joshua Heagle <joshuaheagle@gmail.com> (https://joshuaheagle.com)",
|
|
24
|
+
"license": "GPL-3.0-or-later",
|
|
25
|
+
"bugs": {
|
|
26
|
+
"url": "https://github.com/jheagle/test-fs/issues"
|
|
27
|
+
},
|
|
28
|
+
"homepage": "https://github.com/jheagle/test-fs#readme",
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"fs": "^0.0.1-security",
|
|
31
|
+
"vinyl-source-stream": "^2.0.0"
|
|
32
|
+
},
|
|
33
|
+
"devDependencies": {
|
|
34
|
+
"@babel/core": "^7.23.7",
|
|
35
|
+
"@babel/plugin-transform-modules-commonjs": "^7.23.3",
|
|
36
|
+
"@babel/preset-typescript": "^7.23.3",
|
|
37
|
+
"babel-jest": "^29.7.0",
|
|
38
|
+
"browserify": "^17.0.0",
|
|
39
|
+
"glob": "^10.3.10",
|
|
40
|
+
"gulp": "^4.0.2",
|
|
41
|
+
"gulp-babel": "^8.0.0",
|
|
42
|
+
"gulp-rename": "^2.0.0",
|
|
43
|
+
"gulp-standard": "^14.0.0",
|
|
44
|
+
"gulp-typescript": "^6.0.0-alpha.1",
|
|
45
|
+
"gulp-uglify-es": "^3.0.0",
|
|
46
|
+
"jest": "^29.7.0",
|
|
47
|
+
"jsdoc-to-markdown": "^8.0.0",
|
|
48
|
+
"merge2": "^1.4.1"
|
|
49
|
+
},
|
|
50
|
+
"engines": {
|
|
51
|
+
"node": ">=10.2.1"
|
|
52
|
+
},
|
|
53
|
+
"files": [
|
|
54
|
+
"browser",
|
|
55
|
+
"dist",
|
|
56
|
+
"gulpfile.js"
|
|
57
|
+
]
|
|
58
|
+
}
|