UNPKG

rnsst

Version:

React Native Storybook Screeshot Tests with Detox

44 lines (43 loc) 1.81 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); global.WebSocket = require('ws'); // TODO: is this still necessary? const core_events_1 = require("@storybook/core-events"); const channel_websocket_1 = require("@storybook/channel-websocket"); const websockets_1 = require("./websockets"); class RnsstChannel { constructor(port) { this.notifyStorySet = null; this.stop = () => { this.channel.removeAllListeners(); this.server.stop(); }; this.onStoryRendered = () => { if (this.notifyStorySet) { this.notifyStorySet(); this.notifyStorySet = null; } }; this.getStoryList = () => { console.log('Fetching stories'); this.channel.emit(core_events_1.default.GET_STORIES); return new Promise((resolve) => { // Wait till storybook sends us story list this.channel.on(core_events_1.default.SET_STORIES, ({ stories }) => { console.log('Story list received'); resolve(stories); }); }); }; this.setStory = (storyId) => { return new Promise((resolve) => { this.notifyStorySet = resolve; this.channel.emit(core_events_1.default.SET_CURRENT_STORY, { storyId }); }); }; this.server = new websockets_1.default(port); this.channel = (0, channel_websocket_1.default)({ url: this.server.getUrl(), async: false, onError: () => void 0 }); console.log(`Running Storybook server on ${this.server.getUrl()}`); this.channel.on(core_events_1.default.STORY_RENDERED, this.onStoryRendered); } } exports.default = RnsstChannel;