-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(jest): update snapshot resolver
- Loading branch information
1 parent
cfc8fcb
commit 3a718ec
Showing
74 changed files
with
247 additions
and
277 deletions.
There are no files selected for viewing
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
lib |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"name": "jest-taro-helper", | ||
"version": "3.6.6", | ||
"description": "jest helper for taro", | ||
"private": true, | ||
"main": "index.js", | ||
"files": [ | ||
"lib" | ||
], | ||
"scripts": { | ||
"build": "tsc", | ||
"dev": "tsc -w" | ||
}, | ||
"keywords": [], | ||
"author": "", | ||
"license": "ISC", | ||
"devDependencies": { | ||
"@jest/test-sequencer": "^29.5.0", | ||
"jest-runner": "^29.5.0", | ||
"typescript": "^4.7.4", | ||
"pretty-format": "^29.5.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import type { Test } from 'jest-runner' | ||
|
||
const Sequencer = require('@jest/test-sequencer').default | ||
|
||
export default class CustomSequencer extends Sequencer { | ||
sort (tests: Test[]) { | ||
const copyTests = Array.from(tests) | ||
return copyTests.sort((testA, testB) => testA.path.localeCompare(testB.path)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import * as path from 'path' | ||
|
||
const TEST_DIR = '__tests__' | ||
const SNAPSHOT_DIR = '__snapshots__' | ||
|
||
export const resolveSnapshotPath = (testPath: string, snapshotExtension: string) => { | ||
return testPath.replace(TEST_DIR, SNAPSHOT_DIR) + snapshotExtension | ||
} | ||
|
||
export const resolveTestPath = (snapshotPath: string, snapshotExtension: string) => { | ||
return snapshotPath.replace(snapshotExtension, '').replace(SNAPSHOT_DIR, TEST_DIR) | ||
} | ||
|
||
export const testPathForConsistencyCheck = path.posix.join( | ||
'consistency_check', | ||
TEST_DIR, | ||
'example.test.js' | ||
) | ||
|
||
export default { | ||
resolveSnapshotPath, | ||
resolveTestPath, | ||
testPathForConsistencyCheck | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import * as os from 'os' | ||
// import type { Config, Refs, Printer } from 'pretty-format' | ||
|
||
export const print = (val: string) => { | ||
// Note: 对齐各平台的路径分隔符 | ||
return val.replace(/\\*\*\sfilePath:\s(.*)\s\*\*\//g, (replaceValue) => replaceValue.replace(/\\/g, '/')) | ||
} | ||
|
||
export const parseSnapshotByFilePath = (val: string) => { | ||
const arr = val.split(new RegExp(os.EOL + '|\n')) | ||
let key = '' | ||
return arr.reduce((acc, cur) => { | ||
if (cur.startsWith('/** filePath:')) { | ||
key = cur.replace(/\\/g, '/') | ||
acc[key] = '' | ||
} else { | ||
acc[key] ||= '' | ||
if (acc[key] !== '') { | ||
acc[key] += '\n' | ||
} | ||
acc[key] += cur | ||
} | ||
return acc | ||
}, {}) | ||
} | ||
|
||
export const snapshotObject2String = (val: Record<string, string>) => { | ||
return `"\n${Object.entries(val) | ||
.sort(([key1], [key2]) => key1.localeCompare(key2)) | ||
.filter(([key]) => key !== '') | ||
.map(([key, value]) => `${key}\n${value}`) | ||
.join('\n')}"` | ||
} | ||
|
||
export const serialize = ( | ||
val: any, | ||
// config: Config, | ||
// indentation: string, | ||
// depth: number, | ||
// refs: Refs, | ||
// printer: Printer, | ||
) => { | ||
if (typeof val === 'string') { | ||
return snapshotObject2String(parseSnapshotByFilePath(val)) | ||
} | ||
return val | ||
} | ||
|
||
export const test = (val: unknown) => typeof val === 'string' | ||
|
||
export default { | ||
// print, | ||
serialize, | ||
test, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"extends": "../../tsconfig.root.json", | ||
"compilerOptions": { | ||
"baseUrl": ".", | ||
"outDir": "lib", | ||
"rootDir": "./src", | ||
"module": "commonjs" | ||
}, | ||
"include": ["./src"], | ||
"exclude": ["./src/__tests__"] | ||
} |
Empty file.
Empty file.
Empty file.
Empty file modified
0
...-helper/swc/plugin-define-config/target/wasm32-wasi/release/swc_plugin_define_config.wasm
100755 → 100644
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -523,6 +523,13 @@ require("./taro"); | |
/** filePath: dist/app.wxss **/ | ||
/** filePath: dist/assets/nav_red.png **/ | ||
�PNG | ||