-
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: unified artifacts handling (#2)
- Loading branch information
Showing
14 changed files
with
208 additions
and
6 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
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 |
---|---|---|
@@ -1,3 +1,15 @@ | ||
const assert = require('assert'); | ||
const listener = require('detox-allure2-adapter'); | ||
assert(typeof listener === 'function', 'detox-allure2-adapter should have a function as its default export'); | ||
|
||
const DetoxAllurePathBuilder = require('detox-allure2-adapter/path-builder'); | ||
assert(typeof DetoxAllurePathBuilder === 'function', 'detox-allure2-adapter/path-builder should have a class as its default export'); | ||
assert(new DetoxAllurePathBuilder instanceof DetoxAllurePathBuilder, 'detox-allure2-adapter/path-builder should have a class as its default export'); | ||
|
||
const presetAllure = require('detox-allure2-adapter/preset-allure'); | ||
assert(typeof presetAllure === 'object', 'detox-allure2-adapter/preset-allure should have an object as its default export'); | ||
assert(typeof presetAllure.testCase === 'object', 'detox-allure2-adapter/preset-allure should have an object as its default export'); | ||
|
||
const presetDetox = require('detox-allure2-adapter/preset-detox'); | ||
assert(typeof presetDetox === 'object', 'detox-allure2-adapter/preset-detox should have an object as its default export'); | ||
assert(typeof presetDetox.artifacts === 'object', 'detox-allure2-adapter/preset-detox should have an object as its default export'); |
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 |
---|---|---|
@@ -1,4 +1,16 @@ | ||
import assert from 'assert'; | ||
import listener from 'detox-allure2-adapter'; | ||
import DetoxAllurePathBuilder from 'detox-allure2-adapter/path-builder'; | ||
import presetAllure from 'detox-allure2-adapter/preset-allure'; | ||
import presetDetox from 'detox-allure2-adapter/preset-detox'; | ||
|
||
assert(typeof listener === 'function', 'detox-allure2-adapter should have a function as its default export'); | ||
|
||
assert(typeof DetoxAllurePathBuilder === 'function', 'detox-allure2-adapter/path-builder should have a class as its default export'); | ||
assert(new DetoxAllurePathBuilder instanceof DetoxAllurePathBuilder, 'detox-allure2-adapter/path-builder should have a class as its default export'); | ||
|
||
assert(typeof presetAllure === 'object', 'detox-allure2-adapter/preset-allure should have an object as its default export'); | ||
assert(typeof presetAllure.testCase === 'object', 'detox-allure2-adapter/preset-allure should have an object as its default export'); | ||
|
||
assert(typeof presetDetox === 'object', 'detox-allure2-adapter/preset-detox should have an object as its default export'); | ||
assert(typeof presetDetox.artifacts === 'object', 'detox-allure2-adapter/preset-detox should have an object as its default export'); |
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 |
---|---|---|
@@ -1,8 +1,15 @@ | ||
import type { ReporterOptions } from 'jest-allure2-reporter'; | ||
|
||
import listener from 'detox-allure2-adapter'; | ||
import DetoxAllurePathBuilder from 'detox-allure2-adapter/path-builder'; | ||
import presetAllure from 'detox-allure2-adapter/preset-allure'; | ||
import presetDetox from 'detox-allure2-adapter/preset-detox'; | ||
import { EnvironmentListenerFn } from 'jest-environment-emit'; | ||
|
||
function assertType<T>(_actual: T): void { | ||
// no-op | ||
} | ||
|
||
assertType<EnvironmentListenerFn>(listener); | ||
assertType<DetoxAllurePathBuilder>(new DetoxAllurePathBuilder()); | ||
assertType<ReporterOptions>(presetAllure); |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = require('./dist/path-builder').default; |
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,5 @@ | ||
import index from './dist/path-builder.js'; | ||
|
||
const { default: PathBuilder } = index; | ||
|
||
export default PathBuilder; |
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 @@ | ||
module.exports = require('./dist/preset/allure').default; |
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,5 @@ | ||
import index from './dist/preset/allure.js'; | ||
|
||
const { default: preset } = index; | ||
|
||
export default preset; |
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 @@ | ||
module.exports = require('./dist/preset/detox').default; |
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,5 @@ | ||
import index from './dist/preset/detox.js'; | ||
|
||
const { default: preset } = index; | ||
|
||
export default preset; |
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,21 @@ | ||
import crypto from 'node:crypto'; | ||
import fs from 'node:fs'; | ||
import os from 'node:os'; | ||
import path from 'node:path'; | ||
|
||
export default class DetoxAllurePathBuilder { | ||
#temporaryDirectory: string; | ||
|
||
constructor() { | ||
this.#temporaryDirectory = fs.mkdtempSync(os.tmpdir() + path.sep + 'detox-artifacts-'); | ||
} | ||
|
||
/** @returns {string} */ | ||
buildPathForTestArtifact(artifactName: string) { | ||
return path.join( | ||
this.#temporaryDirectory, | ||
crypto.randomBytes(16).toString('hex'), | ||
artifactName, | ||
); | ||
} | ||
} |
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,83 @@ | ||
// eslint-disable-next-line import/no-internal-modules | ||
import { config, session } from 'detox/internals'; | ||
import type { | ||
KeyedParameterCustomizer, | ||
ReporterOptions, | ||
TestCaseCustomizer, | ||
TestCaseExtractorContext, | ||
} from 'jest-allure2-reporter'; | ||
|
||
const historyId: TestCaseCustomizer['historyId'] = ({ value }): string => { | ||
const { type } = config.device; | ||
const platform = type.split('.')[0]; | ||
return `${platform}:${value}`; | ||
}; | ||
|
||
const device: KeyedParameterCustomizer<unknown> = (): string | undefined => { | ||
const { type, device } = config.device as any; | ||
|
||
switch (type) { | ||
case 'ios.simulator': { | ||
return [device.type, device.os].filter(Boolean).join(', ') || 'iOS Simulator'; | ||
} | ||
case 'android.emulator': { | ||
return device.avdName || 'Android Emulator'; | ||
} | ||
case 'android.genycloud': { | ||
return device.recipeName || 'Genymotion SaaS'; | ||
} | ||
default: { | ||
return; | ||
} | ||
} | ||
}; | ||
|
||
const status: TestCaseCustomizer<TestCaseExtractorContext>['status'] = ({ | ||
testCase: { failureMessages }, | ||
value, | ||
}) => { | ||
if (value !== 'broken') { | ||
return value; | ||
} | ||
|
||
return failureMessages.every((x) => x.includes('Test Failed:')) ? 'failed' : 'broken'; | ||
}; | ||
|
||
const options: ReporterOptions = { | ||
resultsDir: config.artifacts?.rootDir ?? 'artifacts', | ||
overwrite: session.testSessionIndex === 0, | ||
attachments: { | ||
fileHandler: 'copy', | ||
}, | ||
testCase: { | ||
historyId, | ||
status, | ||
parameters: { | ||
device, | ||
}, | ||
}, | ||
testFile: { | ||
historyId, | ||
parameters: { | ||
device, | ||
}, | ||
}, | ||
testRun: { | ||
ignored: ({ aggregatedResult }) => | ||
aggregatedResult.numFailedTests === 0 && aggregatedResult.numFailedTestSuites === 0, | ||
attachments: [ | ||
{ | ||
name: 'detox.log', | ||
type: 'text/plain', | ||
source: 'detox.log', | ||
}, | ||
{ | ||
name: 'detox.trace.json', | ||
type: 'application/json', | ||
source: 'detox.trace.json', | ||
}, | ||
], | ||
}, | ||
}; | ||
|
||
export default options; |
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 @@ | ||
const config: Partial<Detox.DetoxConfig> = { | ||
artifacts: { | ||
rootDir: 'artifacts/', | ||
pathBuilder: 'detox-allure2-adapter/path-builder', | ||
plugins: { | ||
log: 'failing', | ||
screenshot: { | ||
enabled: true, | ||
keepOnlyFailedTestsArtifacts: true, | ||
shouldTakeAutomaticSnapshots: true, | ||
takeWhen: { | ||
testStart: false, | ||
testFailure: true, | ||
testDone: false, | ||
appNotReady: true, | ||
}, | ||
}, | ||
uiHierarchy: 'enabled', | ||
}, | ||
}, | ||
}; | ||
|
||
export default config as object; |