From 1658e1dd64460ce68e489573abbe8b7ee1765fd4 Mon Sep 17 00:00:00 2001 From: Anton Golub Date: Fri, 15 Mar 2024 21:58:06 +0300 Subject: [PATCH] chore: rm redundant assets --- test/fixtures/foo.json | 3 - test/lint/.eslintrc.json | 4 - test/ts/index.test.ts | 12 --- test/ts/spawn.test.ts | 65 ---------------- test/ts/x.test.ts | 161 --------------------------------------- test/ts/zurk.test.ts | 25 ------ 6 files changed, 270 deletions(-) delete mode 100644 test/fixtures/foo.json delete mode 100644 test/lint/.eslintrc.json delete mode 100644 test/ts/index.test.ts delete mode 100644 test/ts/spawn.test.ts delete mode 100644 test/ts/x.test.ts delete mode 100644 test/ts/zurk.test.ts diff --git a/test/fixtures/foo.json b/test/fixtures/foo.json deleted file mode 100644 index dbf5d12..0000000 --- a/test/fixtures/foo.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "data": "foobar" -} \ No newline at end of file diff --git a/test/lint/.eslintrc.json b/test/lint/.eslintrc.json deleted file mode 100644 index eba4e6f..0000000 --- a/test/lint/.eslintrc.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "extends": ["eslint-config-qiwi"], - "rules": {} -} diff --git a/test/ts/index.test.ts b/test/ts/index.test.ts deleted file mode 100644 index cf8dee9..0000000 --- a/test/ts/index.test.ts +++ /dev/null @@ -1,12 +0,0 @@ -import * as assert from 'node:assert' -import { describe, it } from 'node:test' -import { invoke, zurk, $, buildCmd } from '../../main/ts' - -describe('index', () => { - it('has proper exports', () => { - assert.equal(typeof $, 'function') - assert.equal(typeof zurk, 'function') - assert.equal(typeof invoke, 'function') - assert.equal(typeof buildCmd, 'function') - }) -}) diff --git a/test/ts/spawn.test.ts b/test/ts/spawn.test.ts deleted file mode 100644 index 132733a..0000000 --- a/test/ts/spawn.test.ts +++ /dev/null @@ -1,65 +0,0 @@ -import * as assert from 'node:assert' -import { describe, it } from 'node:test' -import { invoke, normalizeCtx, TSpawnCtx, TSpawnResult } from '../../main/ts/spawn.js' -import { makeDeferred } from '../../main/ts/util.js' - -describe('invoke()', () => { - it('calls a given cmd', async () => { - const results = [] - const callback: TSpawnCtx['callback'] = (_err, result) => results.push(result.stdout) - const { promise, resolve, reject } = makeDeferred() - - invoke(normalizeCtx({ - sync: true, - cmd: 'echo', - args: ['hello'], - callback - })) - - invoke(normalizeCtx({ - sync: false, - cmd: 'echo', - args: ['world'], - callback(err, result) { - err ? reject(err) : resolve(result) - } - })) - - await promise.then((result) => callback(null, result)) - - console.log(results) - }) - - it('supports stdin injection', async () => { - const {promise, resolve, reject} = makeDeferred() - const input = '{"name": "world"}' - invoke(normalizeCtx({ - sync: false, - input, - cmd: 'jq', - args: ['-r', '.name'], - callback(err, result) { - err ? reject(err) : resolve(result.stdout) - } - })) - - const name = await promise - assert.equal(name.trim(), 'world') - }) -}) - -describe('normalizeCtx()', () => { - it('normalizes ctx', () => { - const cwds = ['a', 'b', 'c'] - const ctx = { - cmd: 'foo', - get cwd () { - return cwds.shift() || process.cwd() - }, - } - const normalized = normalizeCtx(ctx) - assert.equal(normalized.cwd, 'a') - assert.equal(normalized.cwd, 'b') - assert.equal(normalized.cwd, 'c') - }) -}) diff --git a/test/ts/x.test.ts b/test/ts/x.test.ts deleted file mode 100644 index 3845f7d..0000000 --- a/test/ts/x.test.ts +++ /dev/null @@ -1,161 +0,0 @@ -import * as assert from 'node:assert' -import * as fs from 'node:fs' -import * as path from 'node:path' -import * as os from 'node:os' -import { describe, it } from 'node:test' -import { $ } from '../../main/ts/x.js' -import { Stream } from 'node:stream' - -const __dirname = new URL('.', import.meta.url).pathname -const fixtures = path.resolve(__dirname, '../fixtures') -const tempy = fs.mkdtempSync(path.join(os.tmpdir(), 'tempy-')) -const onStreamFinish = (stream: Stream) => new Promise((resolve) => stream.on('finish', resolve)) -const throwError = (err: any = new Error('should have thrown')) => { throw err } - -describe('$()', () => { - it('supports async flow', async () => { - const p = $`echo foo` - const o1 = (await p).toString() - const o2 = await p.stdout - - assert.equal(o1, 'foo') - assert.equal(o2.trim(), 'foo') - assert.equal(await p.status, 0) - }) - - it('supports sync flow', () => { - const p = $({sync: true})`echo foo` - const o1 = p.toString() - const o2 = p.stdout - - assert.equal(o1, 'foo') - assert.equal(o2.trim(), 'foo') - }) - - it('handles promises in cmd literal', async () => { - const example = $`echo example` - - // eslint-disable-next-line sonarjs/no-nested-template-literals - assert.equal((await $`echo ${example} ${$`echo and`} ${await example}`) - .toString(), 'example and example') - }) - - it('supports stdin', async () => { - const input = '{"name": "foo"}' - const name = await $({input})`jq -r .name` - assert.equal(name.toString().trim(), 'foo') - - const stdin = fs.createReadStream(path.join(fixtures, 'foo.json')) - const data = await $({stdin})`jq -r .data` - assert.equal(data.toString().trim(), 'foobar') - - const p = $`echo "5\\n3\\n1\\n4\\n2"` - const sorted = $({input: p})`sort` - - assert.equal((await sorted).toString(), '1\n2\n3\n4\n5') - }) - - it('supports presets', () => { - const $$ = $({sync: true, cmd: 'echo foo'}) - const $$$ = $$({cmd: 'echo bar'}) - const p1 = $$() - const p2 = $$$() - const p3 = $$`echo baz` - const p4 = $$$({cmd: 'echo qux'})() - const o1 = p1.stdout - const o2 = p2.stdout - const o3 = p3.stdout - const o4 = p4.stdout - - assert.equal(o1.trim(), 'foo') - assert.equal(o2.trim(), 'bar') - assert.equal(o3.trim(), 'baz') - assert.equal(o4.trim(), 'qux') - }) -}) - -describe('mixins', () => { - describe('kill', () => { - it('handles `kill`', async () => { - const p = $({nothrow: true})`sleep 10` - let killed - setTimeout(() => killed = p.kill(), 25) - - const { error } = await p - const signal = await killed - - assert.equal(signal, 'SIGTERM') - assert.equal(error.message, 'Command failed with signal SIGTERM') - }) - - it('handles `abort`', async () => { - const p = $({nothrow: true})`sleep 10` - setTimeout(() => p.abort(), 25) - - const { error } = await p - - assert.equal(error.message, 'The operation was aborted') - }) - }) - - describe('timeout', () => { - it('handles `timeout` as option', async () => { - const p = $({ timeout: 25, timeoutSignal: 'SIGALRM', nothrow: true })`sleep 10` - - const { error } = await p - assert.equal(error.message, 'Command failed with signal SIGALRM') - }) - - it('handles `timeout` as promise setter', async () => { - const p = $`sleep 10` - p.timeoutSignal = 'SIGALRM' - p.timeout = 25 - p._ctx.nothrow = true - - const { error } = await p - assert.equal(error.message, 'Command failed with signal SIGALRM') - }) - }) - - describe('pipe', () => { - it('supports async flow', async () => { - const result = $`echo "5\\n3\\n1\\n4\\n2"` - const expected = '1\n2\n3\n4\n5' - const writable1 = fs.createWriteStream(path.join(tempy, 'output1.txt')) - const writable2 = fs.createWriteStream(path.join(tempy, 'output2.txt')) - const w1 = onStreamFinish(writable1) - const w2 = onStreamFinish(writable1) - - const piped0 = result.pipe`sort | cat` - const piped1 = result.pipe`sort`.pipe`cat` - const piped2 = result.pipe(writable2) - const piped3 = result.pipe($`sort`) - const piped4 = (await result).pipe`sort` - const piped5 = result.pipe($`sort`) - const piped6 = (await result.pipe`sort`).pipe(writable1) - - assert.equal(piped6, writable1) - assert.equal(piped2, writable2) - assert.equal((await piped0).toString(), expected) - assert.equal((await piped1).toString(), expected) - assert.equal((await piped3).toString(), expected) - assert.equal((await piped4).toString(), expected) - assert.equal((await piped5).toString(), expected) - - await w1 - await w2 - assert.equal(fs.readFileSync(path.join(tempy, 'output1.txt'), 'utf8').trim(), expected) - assert.equal(fs.readFileSync(path.join(tempy, 'output2.txt'), 'utf8').trim(), '5\n3\n1\n4\n2') - }) - - it('supports sync flow', async () => { - const result = $({sync: true})`echo "5\\n3\\n1\\n4\\n2"` - assert.equal(result.toString().trim(), '5\n3\n1\n4\n2') - - const expected = '1\n2\n3\n4\n5' - const piped = result.pipe`sort` - - assert.equal(piped.toString(), expected) - }) - }) -}) diff --git a/test/ts/zurk.test.ts b/test/ts/zurk.test.ts deleted file mode 100644 index d001c8c..0000000 --- a/test/ts/zurk.test.ts +++ /dev/null @@ -1,25 +0,0 @@ -import * as assert from 'node:assert' -import { describe, it } from 'node:test' -import { zurk, isZurk, isZurkPromise } from '../../main/ts/zurk.js' - -describe('zurk()', () => { - it('sync returns Zurk instance', async () => { - const result = zurk({ sync: true, cmd: 'echo', args: ['foo']}) - assert.equal(result.toString(), 'foo') - assert.equal(result.stdout, 'foo\n') - assert.equal(result.status, 0) - assert.equal(result.signal, null) - assert.ok(isZurk(result)) - }) - - it('async returns ZurkPromise', async () => { - const result = zurk({ sync: false, cmd: 'echo', args: ['foo']}) - assert.equal((await result).toString(), 'foo') - assert.equal((await result).stdout, 'foo\n') - assert.equal(await result.stdout, 'foo\n') - assert.equal(await result.status, 0) - assert.equal(await result.signal, null) - assert.ok(isZurkPromise(result)) - assert.ok(isZurk(await result)) - }) -})