All files / watch / runTest.ts

100.00% Branches 0/0
9.09% Lines 2/22
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
 
 
 
 
x2
x2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

























import type { Meta } from '../index.ts';
import type { ChildProcess } from '../deps.ts';
import { Fn, wordWrap, msec, entrypoint as entry } from '../format.ts';
import { orange, bold, gray, blue, yellow } from '../format/ansi.ts';
import { getCwd, resolvePath, realpathSync, stdout, stderr, watchFs,
  execFile, stripVTControlCharacters, execImpl } from '../deps.ts';
/** Run a test suite on file update. */
export async function runTest (_kind: string, _paths: string[], ...args: unknown[]) {
  if (args.length === 0) args[0] = './test.ts';
  try {
    const run: ChildProcess = await new Promise((resolve, reject)=>{
      const run = execFile(args[0] as string);
      run.once('error', reject);
      run.once('spawn', () => {
        run.stdout.pipe(stdout);
        run.stderr.pipe(stderr);
        resolve(run); run.off('error', reject);
      });
    });
    await new Promise((resolve, reject)=>{
      run.once('error', reject);
      run.once('close', () => { resolve(null); run.off('error', reject); });
    })
  } catch (e) {
    console.error(e);
  }
};