UNPKG

@cucumber/cucumber

Version:

The official JavaScript implementation of Cucumber.

35 lines 1.89 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.setupEnvironment = setupEnvironment; exports.teardownEnvironment = teardownEnvironment; const node_path_1 = __importDefault(require("node:path")); const node_stream_1 = require("node:stream"); const fs_1 = __importDefault(require("mz/fs")); const reindent_template_literals_1 = require("reindent-template-literals"); const messages_1 = require("@cucumber/messages"); const newId = messages_1.IdGenerator.uuid(); async function setupEnvironment() { const cwd = node_path_1.default.join(__dirname, '..', '..', 'tmp', `api_${newId()}`); await fs_1.default.mkdir(node_path_1.default.join(cwd, 'features'), { recursive: true }); await fs_1.default.writeFile(node_path_1.default.join(cwd, 'features', 'test.feature'), (0, reindent_template_literals_1.reindent)(`Feature: test fixture Scenario: one Given a step Then another step`)); await fs_1.default.writeFile(node_path_1.default.join(cwd, 'features', 'steps.ts'), (0, reindent_template_literals_1.reindent)(`import { Given, Then } from '../../../src' Given('a step', function () {}) Then('another step', function () {})`)); await fs_1.default.writeFile(node_path_1.default.join(cwd, 'cucumber.mjs'), `export default {paths: ['features/test.feature'], requireModule: ['ts-node/register'], require: ['features/steps.ts']}`); const stdout = new node_stream_1.PassThrough(); return { cwd, stdout }; } async function teardownEnvironment(environment) { return new Promise((resolve) => { fs_1.default.rm(environment.cwd, { recursive: true }, resolve); }).then(() => { environment.stdout.end(); }); } //# sourceMappingURL=test_helpers.js.map