UNPKG

@sprucelabs/test-utils

Version:

Helpful utilities to make asserting more complicated conditions quick and easy! ⚡️

65 lines (64 loc) 2.01 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const path_1 = __importDefault(require("path")); class AbstractSpruceTest { constructor() { //instance declariations this.cwd = process.cwd(); } static async beforeAll() { this.cwd = process.cwd(); } static async afterAll() { } static async beforeEach() { } static async afterEach() { } static resolvePath(...filePath) { const cwd = this.cwd; let builtPath = path_1.default.join(...filePath); if (!cwd) { throw new Error('You must call super.beforeAll().'); } if (builtPath[0] !== '/') { if (builtPath.substr(0, 2) === './') { builtPath = builtPath.substr(1); } builtPath = path_1.default.join(cwd, builtPath); } return builtPath; } static async wait(ms = 1000) { return new Promise((resolve) => { setTimeout(() => resolve(true), ms); }); } static log(...args) { const str = args.map((a) => `${a}`).join(' '); process.stderr.write(str); } async wait(ms = 1000) { return new Promise((resolve) => { setTimeout(() => resolve(true), ms); }); } log(...args) { const str = args.map((a) => `${a}`).join(' '); process.stderr.write(str); } resolvePath(...filePath) { const cwd = this.cwd; let builtPath = path_1.default.join(...filePath); if (builtPath[0] !== '/') { if (builtPath.substr(0, 2) === './') { builtPath = builtPath.substr(1); } builtPath = path_1.default.join(cwd, builtPath); } return builtPath; } async beforeEach() { } async afterEach() { } } exports.default = AbstractSpruceTest;