-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtest-basic.js
More file actions
36 lines (30 loc) · 1020 Bytes
/
test-basic.js
File metadata and controls
36 lines (30 loc) · 1020 Bytes
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
import os from 'node:os';
import { execSync } from 'node:child_process';
import { existsSync, mkdirSync, writeFileSync } from 'node:fs';
import { resolve } from 'node:path';
import packageJson from './package.json' with { type: 'json' };
const TEST_DIR = resolve(os.tmpdir(), 'test-ektest');
if (existsSync(TEST_DIR)) {
if (os.platform() === 'win32') {
execSync(`rmdir /s /q ${TEST_DIR}`, { stdio: 'inherit' });
} else {
execSync(`rm -rf ${TEST_DIR}`, { stdio: 'inherit' });
}
}
mkdirSync(TEST_DIR, { recursive: true });
writeFileSync(resolve(TEST_DIR, 'index.test.js'), `
test('Test function', () => {
expect('2 + 2', 2+2).toBe(4);
});
`);
writeFileSync(resolve(TEST_DIR, 'package.json'), `
{
"name": "test-ektest",
"version": "1.0.0",
"type": "module",
"description": "Test project for ektest",
"main": "index.js"
}
`);
execSync(`npm install --save-dev ${process.cwd()}/ektest-${packageJson.version}.tgz`, { cwd: TEST_DIR });
execSync('npx ektest', { cwd: TEST_DIR, stdio: 'inherit' });