-
-
Notifications
You must be signed in to change notification settings - Fork 21
/
test.js
56 lines (48 loc) · 1.38 KB
/
test.js
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import path from 'node:path';
import test from 'ava';
import {execa} from 'execa';
import stripAnsi from 'strip-ansi';
import {temporaryDirectoryTask} from 'tempy';
import {deleteAsync} from 'del';
import createInkApp from './index.js';
const temporaryProjectTask = async (type, callback) => {
await temporaryDirectoryTask(async temporaryDirectory => {
const projectDirectory = path.join(temporaryDirectory, `test-${type}-app`);
await deleteAsync(projectDirectory);
try {
await callback(projectDirectory);
} finally {
await execa('npm', ['unlink', '--global', `test-${type}-app`]);
}
});
};
test.serial('javascript app', async t => {
await temporaryProjectTask('js', async projectDirectory => {
await createInkApp(projectDirectory, {
typescript: false,
silent: true,
});
const result = await execa('test-js-app');
t.is(stripAnsi(result.stdout).trim(), 'Hello, Stranger');
await t.notThrowsAsync(
execa('npm', ['test'], {
cwd: projectDirectory,
}),
);
});
});
test.serial('typescript app', async t => {
await temporaryProjectTask('ts', async projectDirectory => {
await createInkApp(projectDirectory, {
typescript: false,
silent: true,
});
const result = await execa('test-ts-app');
t.is(stripAnsi(result.stdout).trim(), 'Hello, Stranger');
await t.notThrowsAsync(
execa('npm', ['test'], {
cwd: projectDirectory,
}),
);
});
});