-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3c30270
commit 06d998e
Showing
2 changed files
with
21 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,34 @@ | ||
import { spawn } from 'child_process' | ||
import { existsSync } from 'fs' | ||
import { rm, mkdtemp } from 'fs/promises' | ||
import { tmpdir } from 'os' | ||
import { unlink } from 'fs/promises' | ||
import { resolve, join } from 'path' | ||
|
||
const fixturesDir = resolve(__dirname, 'fixtures') | ||
|
||
async function createTempDir(): Promise<string> { | ||
const tempDir = tmpdir() | ||
const tempDirPrefix = 'po2mo-test' | ||
const tempDirPath = join(tempDir, tempDirPrefix) | ||
|
||
return await mkdtemp(tempDirPath) | ||
} | ||
|
||
async function removeTempDir(tempDirPath: string) { | ||
await rm(tempDirPath, { recursive: true, force: true }) | ||
} | ||
|
||
const tests = [ | ||
{ | ||
name: 'basic', | ||
args: [`./${fixturesDir}/basic/basic.po`], | ||
args: [`${fixturesDir}/basic`], | ||
}, | ||
] | ||
|
||
describe('cli', () => { | ||
for (const test of tests) { | ||
const { name, args } = test | ||
|
||
it(`${name} should convert po to mo properly`, async () => { | ||
const tempDir = await createTempDir() | ||
const { stdout, stderr } = await spawn( | ||
require.resolve('tsx/cli'), | ||
[resolve('../src/bin/index.ts')].concat(args) | ||
const cp = spawn( | ||
`${require.resolve('tsx/cli')}`, | ||
[resolve('./src/bin/index.ts')].concat(args) | ||
) | ||
const code = await new Promise((resolve) => { | ||
cp.on('close', resolve) | ||
}) | ||
|
||
if (stdout) console.log(stdout) | ||
if (stderr) console.error(stderr) | ||
expect(code).toBe(0) | ||
expect(existsSync(join(fixturesDir, name, `${name}.mo`))).toBe(true) | ||
|
||
expect(existsSync(join(tempDir, `${name}.mo`))).toBe(true) | ||
await removeTempDir(tempDir) | ||
await unlink(join(fixturesDir, name, `${name}.mo`)) | ||
}) | ||
} | ||
}) |