Skip to content

Commit f47a60f

Browse files
committed
refactor(tests): move from jest to japa test runner
1 parent 0189f67 commit f47a60f

28 files changed

+6182
-6873
lines changed

LICENSE renamed to LICENSE.md

File renamed without changes.

package-lock.json

Lines changed: 4756 additions & 6107 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 31 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@secjs/utils",
3-
"version": "1.8.8",
3+
"version": "1.8.9",
44
"description": "Utils functions and classes for Node.js",
55
"license": "MIT",
66
"author": "João Lenon <lenon@athenna.io>",
@@ -19,9 +19,11 @@
1919
"pagination"
2020
],
2121
"scripts": {
22-
"test": "npm run lint:fix && cross-env NODE_OPTIONS=--experimental-vm-modules jest --colors --verbose --runInBand",
23-
"test:coverage": "npm run --silent test -- --coverage",
24-
"lint:fix": "eslint \"{src,tests}/**/*.js\" --fix"
22+
"lint:fix": "eslint \"{src,tests}/**/*.js\" --fix",
23+
"test": "npm run --silent lint:fix && node ./tests/index.js",
24+
"test:debug": "cross-env DEBUG=api:* && npm run --silent test",
25+
"test:coverage": "c8 npm run --silent test",
26+
"gen:types": "tsc src/*.js --declaration --allowJs --emitDeclarationOnly --out src/index.js"
2527
},
2628
"files": [
2729
"src/*.js",
@@ -31,8 +33,8 @@
3133
],
3234
"type": "module",
3335
"main": "./src/index.js",
34-
"types": "./src/index.d.ts",
3536
"exports": "./src/index.js",
37+
"types": "./src/index.d.ts",
3638
"imports": {
3739
"#src/*": "./src/*.js",
3840
"#tests/*": "./tests/*.js"
@@ -58,6 +60,12 @@
5860
"youch-terminal": "2.1.3"
5961
},
6062
"devDependencies": {
63+
"@japa/assert": "1.3.4",
64+
"@japa/run-failed-tests": "1.0.7",
65+
"@japa/runner": "2.0.7",
66+
"@japa/spec-reporter": "1.1.12",
67+
"@otris/jsdoc-tsd": "^2.0.11",
68+
"c8": "7.11.2",
6169
"commitizen": "4.2.4",
6270
"cross-env": "7.0.3",
6371
"cz-conventional-changelog": "3.3.0",
@@ -69,9 +77,24 @@
6977
"eslint-plugin-prettier": "4.0.0",
7078
"eslint-plugin-promise": "6.0.0",
7179
"husky": "3.0.9",
72-
"jest": "27.5.1",
7380
"lint-staged": "12.4.1",
74-
"prettier": "2.6.2"
81+
"minimist": "1.2.6",
82+
"prettier": "2.6.2",
83+
"rimraf": "3.0.2",
84+
"tsd-jsdoc": "2.5.0",
85+
"typescript": "4.6.4"
86+
},
87+
"c8": {
88+
"all": true,
89+
"include": [
90+
"src/**/*.js"
91+
],
92+
"reporter": [
93+
"text-summary",
94+
"html"
95+
],
96+
"report-dir": "./tests/Coverage",
97+
"check-coverage": true
7598
},
7699
"husky": {
77100
"hooks": {
@@ -93,30 +116,6 @@
93116
"path": "./node_modules/cz-conventional-changelog"
94117
}
95118
},
96-
"jest": {
97-
"rootDir": ".",
98-
"testMatch": [
99-
"**/tests/**/*Test.js"
100-
],
101-
"transform": {},
102-
"coverageDirectory": "./tests/Coverage",
103-
"testEnvironment": "node",
104-
"moduleNameMapper": {
105-
"#src/(.*)": "<rootDir>/src/$1",
106-
"#tests/(.*)": "<rootDir>/tests/$1",
107-
"chalk": "chalk/source/index.js",
108-
"#ansi-styles": "chalk/source/vendor/ansi-styles/index.js",
109-
"#supports-color": "chalk/source/vendor/supports-color/index.js"
110-
},
111-
"coverageThreshold": {
112-
"global": {
113-
"branches": 80,
114-
"functions": 80,
115-
"lines": 80,
116-
"statements": 80
117-
}
118-
}
119-
},
120119
"prettier": {
121120
"singleQuote": true,
122121
"trailingComma": "all",
@@ -136,8 +135,7 @@
136135
"eslintConfig": {
137136
"env": {
138137
"es2021": true,
139-
"node": true,
140-
"jest": true
138+
"node": true
141139
},
142140
"plugins": [
143141
"prettier"

src/Helpers/Debug.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export class Debug {
1616
/**
1717
* Get the timestamp ms.
1818
*
19+
* @private
1920
* @return {string}
2021
*/
2122
static #getTimestamp() {

src/Helpers/File.js

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,12 @@ export class File {
4343
* @param {boolean?} isCopy
4444
* @return {File}
4545
*/
46-
constructor(filePath, content = null, mockedValues = false, isCopy = false) {
46+
constructor(
47+
filePath,
48+
content = undefined,
49+
mockedValues = false,
50+
isCopy = false,
51+
) {
4752
const { ext, dir, name, base, mime, path } = File.#parsePath(filePath)
4853

4954
/** @type {string} */
@@ -172,7 +177,9 @@ export class File {
172177
}
173178

174179
/**
180+
* Parse the file path.
175181
*
182+
* @private
176183
* @param {string} filePath
177184
* @return {{
178185
* ext: string,
@@ -281,7 +288,7 @@ export class File {
281288
this.fileSize = Parser.sizeToByte(fileStat.size)
282289

283290
if (!options.withContent) {
284-
this.content = null
291+
this.content = undefined
285292

286293
return this
287294
}
@@ -322,7 +329,7 @@ export class File {
322329
writable.write(this.content)
323330

324331
writable.end(() => {
325-
this.content = null
332+
this.content = undefined
326333
this.fileExists = true
327334

328335
resolve(this)
@@ -344,7 +351,7 @@ export class File {
344351
this.fileSize = Parser.sizeToByte(fileStat.size)
345352

346353
if (!options.withContent) {
347-
this.content = null
354+
this.content = undefined
348355

349356
return this
350357
}
@@ -382,11 +389,11 @@ export class File {
382389
throw new NotFoundFileException(this.path)
383390
}
384391

385-
this.content = null
386-
this.createdAt = null
387-
this.accessedAt = null
388-
this.modifiedAt = null
389-
this.fileSize = null
392+
this.content = undefined
393+
this.createdAt = undefined
394+
this.accessedAt = undefined
395+
this.modifiedAt = undefined
396+
this.fileSize = undefined
390397
this.fileExists = false
391398
this.originalFileExists = false
392399

@@ -403,11 +410,11 @@ export class File {
403410
throw new NotFoundFileException(this.path)
404411
}
405412

406-
this.content = null
407-
this.createdAt = null
408-
this.accessedAt = null
409-
this.modifiedAt = null
410-
this.fileSize = null
413+
this.content = undefined
414+
this.createdAt = undefined
415+
this.accessedAt = undefined
416+
this.modifiedAt = undefined
417+
this.fileSize = undefined
411418
this.fileExists = false
412419
this.originalFileExists = false
413420

@@ -662,6 +669,7 @@ export class File {
662669
/**
663670
* Create file values.
664671
*
672+
* @private
665673
* @param {boolean?} mockedValues
666674
* @return {void}
667675
*/

src/Helpers/Folder.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@ export class Folder {
226226
/**
227227
* Parse the folder path.
228228
*
229+
* @private
229230
* @param {string} folderPath
230231
* @return {{path: string, name: string, dir: string}}
231232
*/
@@ -390,10 +391,10 @@ export class Folder {
390391
throw new NotFoundFolderException(this.name)
391392
}
392393

393-
this.createdAt = null
394-
this.accessedAt = null
395-
this.modifiedAt = null
396-
this.folderSize = null
394+
this.createdAt = undefined
395+
this.accessedAt = undefined
396+
this.modifiedAt = undefined
397+
this.folderSize = undefined
397398
this.folderExists = false
398399
this.originalFolderExists = false
399400
this.files = []
@@ -412,10 +413,10 @@ export class Folder {
412413
throw new NotFoundFolderException(this.name)
413414
}
414415

415-
this.createdAt = null
416-
this.accessedAt = null
417-
this.modifiedAt = null
418-
this.folderSize = null
416+
this.createdAt = undefined
417+
this.accessedAt = undefined
418+
this.modifiedAt = undefined
419+
this.folderSize = undefined
419420
this.folderExists = false
420421
this.originalFolderExists = false
421422
this.files = []

src/Helpers/Is.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export class Is {
1717
/**
1818
* Return the kindOf.
1919
*
20+
* @private
2021
* @param {any} value
2122
* @return {any}
2223
*/

src/Helpers/Number.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ export class Number {
6262
}
6363

6464
/**
65-
* Extract the first number inside a string.
65+
* Extract all numbers inside a string and
66+
* return as a unique number.
6667
*
6768
* @param {string} string
6869
* @return {number}

src/Helpers/Path.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,7 @@ export class Path {
302302
const stack = callSite()
303303
const requester = dirname(stack[stackIndex].getFileName()).replace(
304304
'file://',
305+
'',
305306
)
306307

307308
const execDir = normalize(requester.concat(sep, normalize(subPath)))

src/index.d.ts

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,34 @@ export declare class Exec {
155155
}
156156

157157
export declare class File {
158+
public originalDir: string
159+
160+
public originalName: string
161+
162+
public originalBase: string
163+
164+
public originalPath: string
165+
166+
public dir: string
167+
168+
public name: string
169+
170+
public base: string
171+
172+
public path: string
173+
174+
public isCopy: boolean
175+
176+
public originalFileExists: boolean
177+
178+
public fileExists: boolean
179+
180+
public content: Buffer
181+
182+
public mime: string
183+
184+
public extension: string
185+
158186
constructor(
159187
filePath: string,
160188
content?: Buffer,
@@ -221,6 +249,24 @@ export declare class File {
221249
}
222250

223251
export declare class Folder {
252+
public originalDir: string
253+
254+
public originalName: string
255+
256+
public originalPath: string
257+
258+
public dir: string
259+
260+
public name: string
261+
262+
public path: string
263+
264+
public isCopy: boolean
265+
266+
public originalFolderExists: boolean
267+
268+
public folderExists: boolean
269+
224270
constructor(folderPath: string, mockedValues?: boolean, isCopy?: boolean)
225271

226272
static folderSizeSync(folderPath: string): number

0 commit comments

Comments
 (0)