-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: handle uihierarchy and logs (#1)
- Loading branch information
Showing
11 changed files
with
2,476 additions
and
16 deletions.
There are no files selected for viewing
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 |
---|---|---|
|
@@ -131,3 +131,5 @@ dist | |
|
||
# IDE | ||
.idea/ | ||
|
||
!__fixtures__ |
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
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
137 changes: 137 additions & 0 deletions
137
src/file-handlers/__snapshots__/log-handler.test.ts.snap
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,137 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`log handler should move a filtered copy of android.txt 1`] = ` | ||
"07:19:02.046 3455 3583 D DetoxWSClient: Received action 'reactNativeReload' (ID #-1000, params={}) | ||
07:19:02.046 3455 3579 I DetoxDispatcher: Handling action 'reactNativeReload' (ID #-1000)... | ||
07:19:02.048 3455 3579 I DetoxRNExt: Reloading React Native | ||
07:19:02.048 3455 3455 D Detox.RNMarker: REACT_BRIDGE_LOADING_START (null) | ||
07:19:02.048 3455 3455 D Detox.RNMarker: DESTROY_CATALYST_INSTANCE_START (null) | ||
07:19:02.049 3455 3632 D Detox.RNMarker: CREATE_REACT_CONTEXT_START (HermesExecutorRelease) | ||
07:19:02.049 3455 3632 D Detox.RNMarker: PROCESS_PACKAGES_START (null) | ||
07:19:02.050 3455 3632 D Detox.RNMarker: CREATE_MODULE_START (FrescoModule) | ||
07:19:02.050 3455 3632 D Detox.RNMarker: CREATE_MODULE_END (FrescoModule) | ||
07:19:02.051 3455 3632 D Detox.RNMarker: PROCESS_PACKAGES_END (null) | ||
07:19:02.051 3455 3632 D Detox.RNMarker: CREATE_CATALYST_INSTANCE_START (null) | ||
07:19:02.072 3455 3633 D Detox.RNMarker: CREATE_REACT_CONTEXT_END (null) | ||
07:19:02.072 3455 3632 D Detox.RNMarker: CREATE_CATALYST_INSTANCE_END (null) | ||
07:19:02.072 3455 3632 D Detox.RNMarker: PRE_RUN_JS_BUNDLE_START (null) | ||
07:19:02.093 3455 3633 D Detox.RNMarker: RUN_JS_BUNDLE_START (index.android.bundle) | ||
07:19:02.094 3455 3634 D Detox.RNMarker: CREATE_MODULE_START (UIManager) | ||
07:19:02.097 3455 3625 D Detox.RNMarker: DESTROY_CATALYST_INSTANCE_END (null) | ||
07:19:02.099 3455 3633 D Detox.RNMarker: NATIVE_MODULE_SETUP_START (NativePerformanceCxx) | ||
07:19:02.099 3455 3633 D Detox.RNMarker: NATIVE_MODULE_SETUP_START (NativePerformanceObserverCxx) | ||
07:19:02.100 3455 3633 D Detox.RNMarker: NATIVE_MODULE_SETUP_START (RedBox) | ||
07:19:02.100 3455 3633 D Detox.RNMarker: NATIVE_MODULE_SETUP_START (BugReporting) | ||
07:19:02.100 3455 3633 D Detox.RNMarker: NATIVE_MODULE_SETUP_START (HeadlessJsTaskSupport) | ||
07:19:02.100 3455 3633 D Detox.RNMarker: CREATE_MODULE_START (HeadlessJsTaskSupport) | ||
07:19:02.100 3455 3633 D Detox.RNMarker: CREATE_MODULE_END (HeadlessJsTaskSupport) | ||
07:19:02.100 3455 3633 D Detox.RNMarker: NATIVE_MODULE_SETUP_END (HeadlessJsTaskSupport) | ||
07:19:02.100 3455 3633 D Detox.RNMarker: NATIVE_MODULE_SETUP_START (UIManager) | ||
07:19:02.111 3455 3634 D Detox.RNMarker: CREATE_MODULE_END (UIManager) | ||
07:19:02.112 3455 3634 D Detox.RNMarker: REACT_BRIDGE_LOADING_END (null) | ||
07:19:02.112 3455 3455 D DetoxRNLoading: Listener-proxy method called: onReactContextInitialized | ||
07:19:02.112 3455 3455 I DetoxRNLoading: Got new RN-context async'ly through listener | ||
07:19:02.112 3455 3455 D DetoxRNLoading: Listener-proxy method called: equals | ||
07:19:02.113 3455 3579 I DetoxRNIdleRes: Setting up Espresso Idling Resources for React Native | ||
07:19:02.119 3455 3455 D Detox.RNMarker: CREATE_MODULE_START (Timing) | ||
07:19:02.119 3455 3455 D Detox.RNMarker: CREATE_MODULE_END (Timing) | ||
07:19:02.119 3455 3579 D Detox.RNMarker: CREATE_MODULE_START (Networking) | ||
07:19:02.120 3455 3579 D Detox.RNMarker: CREATE_MODULE_END (Networking) | ||
07:19:02.120 3455 3579 D Detox.RNMarker: CREATE_MODULE_START (RNCAsyncStorage) | ||
07:19:02.120 3455 3579 D Detox.RNMarker: CREATE_MODULE_END (RNCAsyncStorage) | ||
07:19:02.120 3455 3579 D DetoxRNHelpers: Native RN module resolution (class com.facebook.react.modules.storage.AsyncStorageModule): no such class | ||
07:19:02.121 3455 3455 D Detox.RNMarker: CREATE_MODULE_START (NativeAnimatedModule) | ||
07:19:02.122 3455 3455 D Detox.RNMarker: CREATE_MODULE_END (NativeAnimatedModule) | ||
07:19:02.122 3455 3579 I DetoxWSClient: Sending out action 'ready' (ID #-1000) | ||
07:19:02.122 3455 3579 I DetoxDispatcher: Done with action 'reactNativeReload' | ||
07:19:02.125 3455 3583 D DetoxWSClient: Received action 'invoke' (ID #4, params={"target":{"type":"Class","value":"com.wix.detox.espresso.EspressoDetox"},"method":"perform","args":[{"type":"Invocation","value":{"target":{"type":"Class","value":"com.wix.detox.espresso.DetoxMatcher"},"method":"matcherForText","args":["Actions",{"type":"boolean","value":false}]}},{"type":"Invocation","value":{"target":{"type":"Class","value":"com.wix.detox.espresso.DetoxViewActions"},"method":"click","args":[]}}]}) | ||
07:19:02.125 3455 3579 I DetoxDispatcher: Handling action 'invoke' (ID #4)... | ||
07:19:02.125 3455 3579 D Detox : class com.wix.detox.espresso.DetoxMatcher, matcherForText, [Actions, false] | ||
07:19:02.125 3455 3579 D Detox : class com.wix.detox.espresso.DetoxViewActions, click, [] | ||
07:19:02.126 3455 3579 D Detox : class com.wix.detox.espresso.EspressoDetox, perform, [(an instance of android.widget.TextView and view.getText() with or without transformation to match: is "Actions" and view has effective visibility <VISIBLE>), com.wix.detox.espresso.action.RNClickAction@8aa38a7] | ||
07:19:02.129 3455 3633 D Detox.RNMarker: NATIVE_MODULE_SETUP_END (UIManager) | ||
07:19:02.130 3455 3633 D Detox.RNMarker: NATIVE_MODULE_SETUP_START (PlatformConstants) | ||
07:19:02.130 3455 3633 D Detox.RNMarker: CREATE_MODULE_START (PlatformConstants) | ||
07:19:02.130 3455 3633 D Detox.RNMarker: CREATE_MODULE_END (PlatformConstants) | ||
07:19:02.131 3455 3633 D Detox.RNMarker: NATIVE_MODULE_SETUP_END (PlatformConstants) | ||
07:19:02.132 3455 3633 D Detox.RNMarker: NATIVE_MODULE_SETUP_START (DeviceInfo) | ||
07:19:02.132 3455 3633 D Detox.RNMarker: CREATE_MODULE_START (DeviceInfo) | ||
07:19:02.132 3455 3633 D Detox.RNMarker: CREATE_MODULE_END (DeviceInfo) | ||
07:19:02.132 3455 3633 D Detox.RNMarker: NATIVE_MODULE_SETUP_END (DeviceInfo) | ||
07:19:02.132 3455 3633 D Detox.RNMarker: NATIVE_MODULE_SETUP_START (DeviceEventManager) | ||
07:19:02.132 3455 3633 D Detox.RNMarker: CREATE_MODULE_START (DeviceEventManager) | ||
07:19:02.132 3455 3633 D Detox.RNMarker: CREATE_MODULE_END (DeviceEventManager) | ||
07:19:02.132 3455 3633 D Detox.RNMarker: NATIVE_MODULE_SETUP_END (DeviceEventManager) | ||
07:19:02.134 3455 3633 D Detox.RNMarker: NATIVE_MODULE_SETUP_START (NativeModule) | ||
07:19:02.134 3455 3633 D Detox.RNMarker: NATIVE_MODULE_SETUP_END (NativeModule) | ||
07:19:02.135 3455 3633 D Detox.RNMarker: NATIVE_MODULE_SETUP_START (PlatformLocalStorage) | ||
07:19:02.135 3455 3633 D Detox.RNMarker: NATIVE_MODULE_SETUP_START (RNC_AsyncSQLiteDBStorage) | ||
07:19:02.135 3455 3633 D Detox.RNMarker: NATIVE_MODULE_SETUP_START (RNCAsyncStorage) | ||
07:19:02.135 3455 3633 D Detox.RNMarker: NATIVE_MODULE_SETUP_END (RNCAsyncStorage) | ||
07:19:02.135 3455 3633 D Detox.RNMarker: NATIVE_MODULE_SETUP_START (RNPermissionsModule) | ||
07:19:02.135 3455 3633 D Detox.RNMarker: CREATE_MODULE_START (RNPermissionsModule) | ||
07:19:02.135 3455 3633 D Detox.RNMarker: CREATE_MODULE_END (RNPermissionsModule) | ||
07:19:02.136 3455 3633 D Detox.RNMarker: NATIVE_MODULE_SETUP_END (RNPermissionsModule) | ||
07:19:02.137 3455 3633 D Detox.RNMarker: NATIVE_MODULE_SETUP_START (ShakeEventEmitter) | ||
07:19:02.139 3455 3633 D Detox.RNMarker: NATIVE_MODULE_SETUP_START (Timing) | ||
07:19:02.140 3455 3633 D Detox.RNMarker: NATIVE_MODULE_SETUP_END (Timing) | ||
07:19:02.145 3455 3633 D Detox.RNMarker: RUN_JS_BUNDLE_END (index.android.bundle) | ||
07:19:02.145 3455 3633 I ReactNativeJS: Running "example | ||
07:19:02.147 3455 3633 I ReactNativeJS: App@render: JS rendering main screen | ||
07:19:02.147 3455 3633 D Detox.RNMarker: NATIVE_MODULE_SETUP_START (SoundManager) | ||
07:19:02.147 3455 3633 D Detox.RNMarker: CREATE_MODULE_START (SoundManager) | ||
07:19:02.147 3455 3633 D Detox.RNMarker: CREATE_MODULE_END (SoundManager) | ||
07:19:02.147 3455 3633 D Detox.RNMarker: NATIVE_MODULE_SETUP_END (SoundManager) | ||
07:19:02.148 3455 3633 D Detox.RNMarker: NATIVE_MODULE_SETUP_START (NativeAnimatedModule) | ||
07:19:02.149 3455 3633 D Detox.RNMarker: NATIVE_MODULE_SETUP_END (NativeAnimatedModule) | ||
07:19:02.149 3455 3633 D Detox.RNMarker: NATIVE_MODULE_SETUP_START (NativeAnimatedTurboModule) | ||
07:19:02.183 3455 3633 D Detox.RNMarker: NATIVE_MODULE_SETUP_START (LaunchArguments) | ||
07:19:02.183 3455 3633 D Detox.RNMarker: NATIVE_MODULE_SETUP_END (LaunchArguments) | ||
07:19:02.212 3455 3455 D Detox.RNMarker: CONTENT_APPEARED (example) | ||
07:19:02.278 3455 3633 I ReactNativeJS: App@render: JS rendering screen | ||
07:19:02.279 3455 3633 D Detox.RNMarker: NATIVE_MODULE_SETUP_START (FrameRateLogger) | ||
07:19:02.279 3455 3633 D Detox.RNMarker: NATIVE_MODULE_SETUP_START (KeyboardObserver) | ||
07:19:02.313 3455 3633 D Detox.RNMarker: NATIVE_MODULE_SETUP_START (ImageLoader) | ||
07:19:02.313 3455 3633 D Detox.RNMarker: CREATE_MODULE_START (ImageLoader) | ||
07:19:02.313 3455 3633 D Detox.RNMarker: CREATE_MODULE_END (ImageLoader) | ||
07:19:02.314 3455 3633 D Detox.RNMarker: NATIVE_MODULE_SETUP_END (ImageLoader) | ||
07:19:02.644 3455 3579 I DetoxWSClient: Sending out action 'invokeResult' (ID #4) | ||
07:19:02.644 3455 3579 I DetoxDispatcher: Done with action 'invoke' | ||
07:19:02.648 3455 3583 D DetoxWSClient: Received action 'invoke' (ID #5, params={"target":{"type":"Class","value":"com.wix.detox.espresso.EspressoDetox"},"method":"perform","args":[{"type":"Invocation","value":{"target":{"type":"Class","value":"com.wix.detox.espresso.DetoxMatcher"},"method":"matcherForText","args":["Tap Me",{"type":"boolean","value":false}]}},{"type":"Invocation","value":{"target":{"type":"Class","value":"androidx.test.espresso.action.ViewActions"},"method":"longClick","args":[]}}]}) | ||
07:19:02.649 3455 3579 I DetoxDispatcher: Handling action 'invoke' (ID #5)... | ||
07:19:02.649 3455 3579 D Detox : class com.wix.detox.espresso.DetoxMatcher, matcherForText, [Tap Me, false] | ||
07:19:02.649 3455 3579 D Detox : class androidx.test.espresso.action.ViewActions, longClick, [] | ||
07:19:02.649 3455 3579 D Detox : class com.wix.detox.espresso.EspressoDetox, perform, [(an instance of android.widget.TextView and view.getText() with or without transformation to match: is "Tap Me" and view has effective visibility <VISIBLE>), androidx.test.espresso.action.GeneralClickAction@eb86cb4] | ||
07:19:02.672 3455 3455 I Detox : UIManagerModule is busy | ||
07:19:03.192 3455 3455 I Detox : UIManagerModule is busy | ||
07:19:03.980 3455 3579 I DetoxWSClient: Sending out action 'invokeResult' (ID #5) | ||
07:19:03.980 3455 3579 I DetoxDispatcher: Done with action 'invoke' | ||
07:19:03.985 3455 3583 D DetoxWSClient: Received action 'invoke' (ID #6, params={"target":{"type":"Class","value":"com.wix.detox.espresso.DetoxAssertion"},"method":"assertMatcher","args":[{"type":"Invocation","value":{"target":{"type":"Class","value":"androidx.test.espresso.Espresso"},"method":"onView","args":[{"type":"Invocation","value":{"target":{"type":"Class","value":"com.wix.detox.espresso.DetoxMatcher"},"method":"matcherForText","args":["Long Press Working!!!",{"type":"boolean","value":false}]}}]}},{"type":"Invocation","value":{"target":{"type":"Class","value":"com.wix.detox.espresso.DetoxMatcher"},"method":"matcherForSufficientlyVisible","args":[{"type":"Integer","value":75}]}}]}) | ||
07:19:03.985 3455 3579 I DetoxDispatcher: Handling action 'invoke' (ID #6)... | ||
07:19:03.985 3455 3579 D Detox : class com.wix.detox.espresso.DetoxMatcher, matcherForText, [Long Press Working!!!, false] | ||
07:19:03.985 3455 3579 D Detox : class androidx.test.espresso.Espresso, onView, [(an instance of android.widget.TextView and view.getText() with or without transformation to match: is "Long Press Working!!!" and view has effective visibility <VISIBLE>)] | ||
07:19:03.986 3455 3579 D Detox : class com.wix.detox.espresso.DetoxMatcher, matcherForSufficientlyVisible, [75] | ||
07:19:03.986 3455 3579 D Detox : class com.wix.detox.espresso.DetoxAssertion, assertMatcher, [androidx.test.espresso.ViewInteraction@c9de7f, (view has effective visibility <VISIBLE> and view.getGlobalVisibleRect() covers at least <75> percent of the view's area)] | ||
07:19:03.989 3455 3455 I ViewInteraction: Checking 'MatchesViewAssertion(Detox){viewMatcher=(view has effective visibility <VISIBLE> and view.getGlobalVisibleRect() covers at least <75> percent of the view's area)}' assertion on view (an instance of android.widget.TextView and view.getText() with or without transformation to match: is "Long Press Working!!!" and view has effective visibility <VISIBLE>) | ||
07:19:03.990 3455 3579 I DetoxWSClient: Sending out action 'invokeResult' (ID #6) | ||
07:19:03.990 3455 3579 I DetoxDispatcher: Done with action 'invoke' | ||
" | ||
`; | ||
exports[`log handler should move a filtered copy of ios.txt 1`] = ` | ||
"11:16:03.010 I example[45997:9baf9a] [com.facebook.react.log:native] Running application example ({ | ||
initialProps = { | ||
}; | ||
rootTag = 1; | ||
11:16:03.290 I example[45997:9baf9a] [com.wix.Detox:WebSocket] Action received: loginSuccess | ||
11:16:03.291 I example[45997:9baf9a] [com.wix.Detox:DetoxManager] Successfully logged in | ||
11:16:03.294 I example[45997:9baf9a] [com.wix.Detox:WebSocket] Action received: isReady | ||
11:16:03.522 E example[45997:9bafd7] [com.facebook.react.log:javascript] Invariant Violation: Slider has been removed from react-native core. It can now be installed and imported from '@react-native-community/slider' instead of 'react-native'. See https://github.com/callstack/react-native-slider | ||
11:16:03.534 I example[45997:9bafd7] [com.facebook.react.log:javascript] Running "example" with {"rootTag":1,"initialProps":{}} | ||
11:16:03.534 E example[45997:9bafd7] [com.facebook.react.log:javascript] Invariant Violation: "example" has not been registered. This can happen if: | ||
11:16:03.725 I example[45997:9baf9a] [com.facebook.react.log:native] Running surface LogBox ({ | ||
initialProps = { | ||
}; | ||
rootTag = 11; | ||
" | ||
`; |
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,2 @@ | ||
export * from './log-handler'; | ||
export * from './zip-handler'; |
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,49 @@ | ||
import fs from 'node:fs'; | ||
import path from 'node:path'; | ||
// eslint-disable-next-line import/no-internal-modules | ||
import type { FileAttachmentContext, FileAttachmentHandler } from 'jest-allure2-reporter/api'; | ||
import { createLogHandler } from './log-handler'; | ||
|
||
describe('log handler', () => { | ||
const movedPath = '/path/to/moved.log'; | ||
|
||
let move: jest.Mock; | ||
let logHandler: FileAttachmentHandler; | ||
let temporaryFiles: string[]; | ||
|
||
beforeAll(() => { | ||
temporaryFiles = []; | ||
}); | ||
|
||
afterAll(() => { | ||
for (const file of temporaryFiles) { | ||
fs.unlinkSync(file); | ||
} | ||
}); | ||
|
||
beforeEach(() => { | ||
move = jest.fn(async (context: FileAttachmentContext) => { | ||
temporaryFiles.push(context.sourcePath); | ||
return movedPath; | ||
}); | ||
|
||
logHandler = createLogHandler({ | ||
fileAttachmentHandlers: { move }, | ||
} as any); | ||
}); | ||
|
||
it.each([['ios.txt'], ['android.txt']])('should move a filtered copy of %s', async (inputLog) => { | ||
const filePath = await logHandler({ | ||
name: 'device.log', | ||
sourcePath: path.join(__dirname, '__fixtures__', inputLog), | ||
mimeType: 'text/plain', | ||
outDir: __dirname, | ||
}); | ||
|
||
expect(filePath).toBe(movedPath); | ||
expect(move).toBeCalledTimes(1); | ||
const filteredLogPath = move.mock.calls[0][0].sourcePath; | ||
const content = fs.readFileSync(filteredLogPath, 'utf8'); | ||
expect(content).toMatchSnapshot(); | ||
}); | ||
}); |
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,70 @@ | ||
/* eslint-disable unicorn/no-array-method-this-argument */ | ||
import crypto from 'node:crypto'; | ||
import fs from 'node:fs'; | ||
import os from 'node:os'; | ||
import path from 'node:path'; | ||
import readline from 'node:readline'; | ||
|
||
// eslint-disable-next-line import/no-internal-modules | ||
import type { AllureRuntimePluginContext, FileAttachmentHandler } from 'jest-allure2-reporter/api'; | ||
|
||
const WHITESPACE_START = /^\s+/; | ||
|
||
export function createLogHandler(pluginContext: AllureRuntimePluginContext): FileAttachmentHandler { | ||
return async function logHandler(context) { | ||
return pluginContext.fileAttachmentHandlers.move({ | ||
...context, | ||
sourcePath: await filterLog(context.sourcePath), | ||
}); | ||
}; | ||
} | ||
|
||
async function filterLog(src: string): Promise<string> { | ||
const seed = crypto.randomBytes(8).toString('hex'); | ||
const dest = path.join(os.tmpdir(), 'detox-allure2-filtered-' + seed + '.log'); | ||
const onError = (error: Error) => console.error('Caught error in detox-allure2-adapter:', error); | ||
|
||
await doFilterLog({ | ||
input: fs.createReadStream(src).on('error', onError), | ||
output: fs.createWriteStream(dest).on('error', onError), | ||
include: ['Detox', 'ReactNativeJS', 'com.facebook.react.log', /\s[EF]\s/], | ||
exclude: ['com.apple.network', '(CFNetwork)'], | ||
transform: (s) => s.replace(/^\S*\s*/, ''), | ||
}); | ||
|
||
return dest; | ||
} | ||
|
||
type FilterLogParams = { | ||
input: fs.ReadStream; | ||
output: fs.WriteStream; | ||
include: (string | RegExp)[]; | ||
exclude: (string | RegExp)[]; | ||
transform: (line: string) => string; | ||
}; | ||
|
||
async function doFilterLog({ input, output, include, exclude, transform }: FilterLogParams) { | ||
return new Promise((resolve) => { | ||
const rl = readline.createInterface({ input }); | ||
|
||
let shouldPrint = false; | ||
rl.on('line', (input) => { | ||
const isWhitespace = WHITESPACE_START.test(input); | ||
shouldPrint = isWhitespace | ||
? shouldPrint | ||
: include.some(test, input) && !exclude.some(test, input); | ||
|
||
const line = isWhitespace ? input : transform(input); | ||
|
||
if (shouldPrint) { | ||
output.write(line + '\n'); | ||
} | ||
}); | ||
|
||
rl.on('close', resolve); | ||
}); | ||
} | ||
|
||
function test(this: string, pattern: string | RegExp) { | ||
return typeof pattern === 'string' ? this.includes(pattern) : pattern.test(this); | ||
} |
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,52 @@ | ||
import fs from 'node:fs'; | ||
|
||
// eslint-disable-next-line import/no-internal-modules | ||
import type { FileAttachmentContext, FileAttachmentHandler } from 'jest-allure2-reporter/api'; | ||
|
||
import { createZipHandler } from './zip-handler'; | ||
|
||
describe('zip handler', () => { | ||
const movedPath = '/path/to/moved.log'; | ||
|
||
let move: jest.Mock; | ||
let logHandler: FileAttachmentHandler; | ||
let temporaryFiles: string[]; | ||
|
||
beforeAll(() => { | ||
temporaryFiles = []; | ||
}); | ||
|
||
afterAll(() => { | ||
for (const file of temporaryFiles) { | ||
fs.unlinkSync(file); | ||
} | ||
}); | ||
|
||
beforeEach(() => { | ||
move = jest.fn(async (context: FileAttachmentContext) => { | ||
temporaryFiles.push(context.sourcePath); | ||
return movedPath; | ||
}); | ||
|
||
logHandler = createZipHandler({ | ||
fileAttachmentHandlers: { move }, | ||
} as any); | ||
}); | ||
|
||
it('should zip a directory', async () => { | ||
const filePath = await logHandler({ | ||
name: 'device.log', | ||
sourcePath: __dirname, | ||
mimeType: 'text/plain', | ||
outDir: __dirname, | ||
}); | ||
|
||
expect(filePath).toBe(movedPath); | ||
expect(move).toHaveBeenCalledWith({ | ||
name: 'device.log.zip', | ||
sourcePath: expect.stringMatching(/\.zip$/), | ||
mimeType: 'application/zip', | ||
outDir: __dirname, | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.