UNPKG

@sprucelabs/test-utils

Version:

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

59 lines (58 loc) 1.71 kB
import path from 'path'; export default 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.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.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.join(...filePath); if (builtPath[0] !== '/') { if (builtPath.substr(0, 2) === './') { builtPath = builtPath.substr(1); } builtPath = path.join(cwd, builtPath); } return builtPath; } async beforeEach() { } async afterEach() { } }