rnsst
Version:
React Native Storybook Screeshot Tests with Detox
36 lines (35 loc) • 1.31 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.runTests = exports.getStories = void 0;
const detox_1 = require("detox");
const IGNORE_PREFIX = '!';
async function getStories(channel, beforeHandler) {
const [storyList] = await Promise.all([channel.getStoryList(), beforeHandler === null || beforeHandler === void 0 ? void 0 : beforeHandler()]);
return storyList;
}
exports.getStories = getStories;
async function runTests(testingLib, channel, stories) {
const storyGroups = Object.entries(groupBy('kind', Object.values(stories)));
for (const group of storyGroups) {
const [kind, stories] = group;
for (const story of stories) {
const { name } = story;
if (name[0] === IGNORE_PREFIX) {
continue;
}
console.log(`Testing ${kind} - ${name}`);
const { id } = story;
await channel.setStory(id);
await (0, detox_1.expect)((0, detox_1.element)(detox_1.by.id(id))).toBeVisible();
await testingLib.testScreenshot(id);
}
}
}
exports.runTests = runTests;
function groupBy(key, arr) {
return arr.reduce((acc, cur) => {
acc[cur[key]] = acc[cur[key]] || [];
acc[cur[key]].push(cur);
return acc;
}, {});
}