mirror of
https://github.com/hanzoai/Detox.git
synced 2026-09-24 16:55:12 +00:00
test(e2e): refactor skip mechanism (#4559)
This commit is contained in:
committed by
GitHub
parent
bf969dbbbc
commit
9e48c62b37
@@ -1,5 +1,4 @@
|
||||
const driver = require('./drivers/actions-driver').actionsScreenDriver;
|
||||
const custom = require('./utils/custom-it');
|
||||
|
||||
describe('Actions', () => {
|
||||
beforeAll(async () => {
|
||||
@@ -227,7 +226,7 @@ describe('Actions', () => {
|
||||
await expect(element(by.id('UniqueId007'))).toBeVisible();
|
||||
});
|
||||
|
||||
custom.it.skipFromRNVersion(71)('should adjust legacy slider and assert its value', async () => {
|
||||
it('@rn71 should adjust legacy slider and assert its value', async () => {
|
||||
const reactSliderId = 'legacySliderWithASimpleID';
|
||||
await expect(element(by.id(reactSliderId))).toHaveSliderPosition(0.25);
|
||||
await element(by.id(reactSliderId)).adjustSliderToPosition(0.75);
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
const { device, element, by } = require('detox');
|
||||
const expect = require('expect').default;
|
||||
const custom = require('./utils/custom-it');
|
||||
|
||||
describe('Attributes', () => {
|
||||
/** @type {Detox.IndexableNativeElement} */
|
||||
@@ -157,7 +156,7 @@ describe('Attributes', () => {
|
||||
});
|
||||
});
|
||||
|
||||
custom.describe.skipFromRNVersion(71)('of a legacy slider', () => {
|
||||
describe('of a legacy slider (@rn71)', () => {
|
||||
beforeAll(() => useMatcher(by.id('legacySliderId')));
|
||||
|
||||
it(':ios: should have a string percent .value, and .normalizedSliderPosition', () => {
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
const { expectToThrow } = require('./utils/custom-expects');
|
||||
const custom = require('./utils/custom-it');
|
||||
|
||||
describe(':ios: Overlay', () => {
|
||||
let showAlertButton;
|
||||
@@ -55,11 +54,11 @@ describe(':ios: Overlay', () => {
|
||||
await dismissAlertButton.tap();
|
||||
});
|
||||
|
||||
custom.it.withFailureIf.iOSWithRNLessThan67('should be able to tap on elements', async () => {
|
||||
it('should be able to tap on elements', async () => {
|
||||
await showOverlayWindowButton.tap();
|
||||
});
|
||||
|
||||
custom.it.withFailureIf.iOSWithRNLessThan67('should be able to scroll elements', async () => {
|
||||
it('should be able to scroll elements', async () => {
|
||||
await verticalScrollView.scrollTo('bottom');
|
||||
await expect(showOverlayWindowButton).not.toBeVisible();
|
||||
});
|
||||
|
||||
@@ -55,6 +55,7 @@ module.exports = async () => {
|
||||
'jest-metadata/environment-listener',
|
||||
'jest-allure2-reporter/environment-listener',
|
||||
require.resolve('detox-allure2-adapter'),
|
||||
require.resolve('./utils/rnSkipper'),
|
||||
]
|
||||
},
|
||||
'testRunner': './test/node_modules/jest-circus/runner',
|
||||
|
||||
@@ -1,71 +0,0 @@
|
||||
const _ = require('lodash');
|
||||
const rnMinorVer = require('../../../src/utils/rn-consts/rn-consts').rnVersion.minor;
|
||||
|
||||
const _it = {
|
||||
withFailureIf: {
|
||||
android: (spec, specFn) => runOrExpectFailByPredicates(spec, specFn, platformIs('android')),
|
||||
iOSWithRNLessThan67: (spec, specFn) => runOrExpectFailByPredicates(spec, specFn, platformIs('ios'), rnVerLessThan(67)),
|
||||
},
|
||||
skipFromRNVersion: (version) => skipFromRNVersion(version),
|
||||
};
|
||||
|
||||
const _describe = {
|
||||
skipFromRNVersion: (version) => describeFromRNVersion(version),
|
||||
}
|
||||
|
||||
function runOrExpectFailByPredicates(spec, specFn, ...predicateFuncs) {
|
||||
it(spec, async function() {
|
||||
if (allPredicatesTrue(predicateFuncs)) {
|
||||
await expectSpecFail(specFn);
|
||||
} else {
|
||||
await runSpec(specFn);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Run the test only if the RN version is {version} or below. Otherwise, skip it.
|
||||
* @returns it or it.skip functions
|
||||
*/
|
||||
function skipFromRNVersion(version) {
|
||||
if (parseInt(rnMinorVer) <= version) {
|
||||
return it;
|
||||
} else {
|
||||
return it.skip;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the test only if the RN version is {version} or below. Otherwise, skip it.
|
||||
* @param version
|
||||
* @returns describe or describe.skip functions
|
||||
*/
|
||||
function describeFromRNVersion(version) {
|
||||
if (parseInt(rnMinorVer) <= version) {
|
||||
return describe;
|
||||
} else {
|
||||
return describe.skip;
|
||||
}
|
||||
}
|
||||
|
||||
const platformIs = (platform) => () => (device.getPlatform() === platform);
|
||||
const rnVerLessThan = (rnVer) => () => (rnMinorVer < rnVer);
|
||||
const allPredicatesTrue = (predicateFuncs) => _.reduce(predicateFuncs, (result, predicate) => (result && predicate()), true);
|
||||
|
||||
async function expectSpecFail(specFn) {
|
||||
try {
|
||||
await runSpec(specFn);
|
||||
} catch (e) {
|
||||
console.log('Successfully caught an expected error:', e);
|
||||
return;
|
||||
}
|
||||
throw new Error('Ran a spec expecting an error, but no error was thrown');
|
||||
}
|
||||
|
||||
const runSpec = (specFn) => specFn();
|
||||
|
||||
module.exports = {
|
||||
it: _it,
|
||||
describe: _describe,
|
||||
};
|
||||
@@ -0,0 +1,21 @@
|
||||
const rn = require('../../../src/utils/rn-consts/rn-consts').rnVersion.minor;
|
||||
|
||||
/** @type {import('jest-environment-emit').EnvironmentListenerFn} */
|
||||
const listener = ({ testEvents }) => {
|
||||
testEvents
|
||||
.on('start_describe_definition', ({ event: { blockName }, state: { currentDescribeBlock }}) => {
|
||||
const match = blockName.match(/@rn(\d+)/i);
|
||||
if (match && match[1] != rn) {
|
||||
currentDescribeBlock.mode = 'skip';
|
||||
}
|
||||
})
|
||||
.on('add_test', ({ event: { testName }, state: { currentDescribeBlock }}) => {
|
||||
const match = testName.match(/@rn(\d+)/i);
|
||||
if (match && match[1] != rn) {
|
||||
const n = currentDescribeBlock.children.length;
|
||||
currentDescribeBlock.children[n - 1].mode = 'skip';
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = listener;
|
||||
Reference in New Issue
Block a user