From bc1f1aecdf25807ecf983bb75ddd88f1e895c3e9 Mon Sep 17 00:00:00 2001 From: Phil Rzewski Date: Wed, 24 Jan 2024 15:36:58 -0800 Subject: [PATCH] Run just the failing test --- packages/zed-node/src/binpath.test.ts | 11 -- packages/zed-node/src/field.test.ts | 32 ------ packages/zed-node/src/zjson.test.ts | 147 -------------------------- packages/zed-node/src/zq.test.ts | 129 ---------------------- 4 files changed, 319 deletions(-) delete mode 100644 packages/zed-node/src/binpath.test.ts delete mode 100644 packages/zed-node/src/field.test.ts delete mode 100644 packages/zed-node/src/zjson.test.ts diff --git a/packages/zed-node/src/binpath.test.ts b/packages/zed-node/src/binpath.test.ts deleted file mode 100644 index 4ab5206988..0000000000 --- a/packages/zed-node/src/binpath.test.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { getZedPath, getZqPath } from './binpath'; - -describe('paths', () => { - it('can find the path to zed', () => { - getZedPath(); - }); - - it('can find the path to zq', () => { - getZqPath(); - }); -}); diff --git a/packages/zed-node/src/field.test.ts b/packages/zed-node/src/field.test.ts deleted file mode 100644 index 217c1faccb..0000000000 --- a/packages/zed-node/src/field.test.ts +++ /dev/null @@ -1,32 +0,0 @@ -import { zq } from './zq'; -import { DefaultContext, Record, createRecord } from '@brimdata/zed-js'; - -jest.setTimeout(60_000); - -test('field path', () => { - const r = createRecord({ id: { person: 'alice' } }); - const f = r.getField(['id', 'person']); - - expect(f?.value.toString()).toBe('alice'); - expect(f?.name).toBe('person'); - expect(f?.path).toEqual(['id', 'person']); -}); - -test('field path with nested named types', async () => { - const objects = await zq({ - input: '{a: {b: {c: "foo"}(=c)}(=b)}(=a)', - as: 'zjson', - }); - const rows = DefaultContext.decode(objects) as Record[]; - const field = rows[0].getField(['a', 'b', 'c']); - expect(field?.path).toEqual(['a', 'b', 'c']); - expect(field?.rootRecord === rows[0]).toBe(true); -}); - -test('field path with nested unnamed types', async () => { - const objects = await zq({ input: '{a: {b: {c: "foo"}}}', as: 'zjson' }); - const rows = DefaultContext.decode(objects) as Record[]; - const field = rows[0].getField(['a', 'b', 'c']); - expect(field?.path).toEqual(['a', 'b', 'c']); - expect(field?.rootRecord === rows[0]).toBe(true); -}); diff --git a/packages/zed-node/src/zjson.test.ts b/packages/zed-node/src/zjson.test.ts deleted file mode 100644 index 6c8ea8885e..0000000000 --- a/packages/zed-node/src/zjson.test.ts +++ /dev/null @@ -1,147 +0,0 @@ -import { zq } from './zq'; -import { getPath } from '@brimdata/sample-data'; -import * as zed from '@brimdata/zed-js'; - -const file = getPath('sample.zson'); - -jest.setTimeout(60_000); - -test('super simple', async () => { - const input = (await zq({ - input: '{hello: "world"}', - as: 'zjson', - })) as zed.zjson.Obj[]; - const decoded = zed.decode(input); - const encoded = zed.encode(decoded); - for (let i = 0; i < input.length; ++i) { - expect(encoded[i]).toEqual(input[i]); - } -}); - -test('super simple 2 typedefs', async () => { - const input: zed.zjson.Obj[] = (await zq({ - input: '{hello: ["world"]}', - as: 'zjson', - })) as zed.zjson.Obj[]; - - const decoded = zed.decode(input); - const encoded = zed.encode(decoded); - for (let i = 0; i < input.length; ++i) { - expect(encoded[i]).toEqual(input[i]); - } -}); - -test('simply type value', async () => { - const input: zed.zjson.Obj[] = (await zq({ - input: '{hello: }', - as: 'zjson', - })) as zed.zjson.Obj[]; - - const decoded = zed.decode(input); - const encoded = zed.encode(decoded); - for (let i = 0; i < input.length; ++i) { - expect(encoded[i]).toEqual(input[i]); - } -}); - -test('decode, then encode', async () => { - const input: zed.zjson.Obj[] = (await zq({ - file, - as: 'zjson', - })) as zed.zjson.Obj[]; - - const decoded = zed.decode(input); - const encoded = zed.encode(decoded); - - for (let i = 0; i < input.length; ++i) { - expect(encoded[i]).toEqual(input[i]); - } -}); - -test('decode, then encode a fused input', async () => { - const input: zed.zjson.Obj[] = (await zq({ - query: 'fuse', - file, - as: 'zjson', - })) as zed.zjson.Obj[]; - - const decoded = zed.decode(input); - const encoded = zed.encode(decoded); - - for (let i = 0; i < input.length; ++i) { - expect(encoded[i]).toEqual(input[i]); - } -}); - -test('decode, encode with type values', async () => { - const input: zed.zjson.Obj[] = (await zq({ - query: '* | count() by typeof(this) | sort count, typeof', - file, - as: 'zjson', - })) as zed.zjson.Obj[]; - - expect(zed.encode(zed.decode(input))).toEqual(input); -}); - -test('types from one search are the same', async () => { - const groupBy = (await zq({ - query: '* | count() by typeof(this) | sort count, typeof', - file, - as: 'zjson', - })) as zed.zjson.Obj[]; - - const list = (await zq({ file, as: 'zjson' })) as zed.zjson.Obj[]; - - const [row1] = zed.decode(groupBy) as zed.Record[]; - const accessType = row1.get('typeof').value; - - const rows = zed.decode(list); - const accessRecords = rows.filter((r) => r.type === accessType); - - expect(accessRecords.map((r) => r.toString())).toEqual([ - '{info:Access List Example,nets:[10.1.1.0/24,10.1.2.0/24]}', - ]); -}); - -test('encode decode a field', async () => { - const input: zed.zjson.Obj[] = (await zq({ - query: '*', - file, - as: 'zjson', - })) as zed.zjson.Obj[]; - - const records = zed.decode(input) as zed.Record[]; - expect.assertions(250); - - records.forEach((rec) => { - rec.flatColumns.forEach((column) => { - const field = rec.getField(column); - if (!field) return; - const after = zed.decode(zed.encode(field)); - expect(field).toEqual(after); - expect(field.value.type === after.value.type).toBe(true); - }); - }); -}); - -test('encode decode a typeof value', async () => { - const input: zed.zjson.Obj[] = (await zq({ - query: 'count() by typeof(this) | sort typeof', - file, - as: 'zjson', - })) as zed.zjson.Obj[]; - - const records = zed.decode(input) as zed.Record[]; - expect.assertions(36); - - records.forEach((rec) => { - rec.flatColumns.forEach((column) => { - const field = rec.getField(column); - if (!field) return; - const after = zed.decode(zed.encode(field)); - if (!field) return; - expect(field).toEqual(after); - expect(field.value.type === after.value.type).toBe(true); - }); - }); -}); diff --git a/packages/zed-node/src/zq.test.ts b/packages/zed-node/src/zq.test.ts index 032375a435..413ee8e49b 100644 --- a/packages/zed-node/src/zq.test.ts +++ b/packages/zed-node/src/zq.test.ts @@ -1,4 +1,3 @@ -import * as Stream from 'stream'; import { createTransformStream, zq } from './zq'; import { getPath } from '@brimdata/sample-data'; import { createReadStream } from 'fs'; @@ -7,102 +6,6 @@ if (process.env['GITHUB_ACTIONS'] === 'true') { jest.setTimeout(30_000); } -test('zq.stream', async () => { - const input = Stream.Readable.from('1 2 3', { encoding: 'utf-8' }); - const zq = createTransformStream({ query: '{num: this}', f: 'zson' }); - let text = ''; - for await (const chunk of input.pipe(zq)) { - if (chunk) text += chunk.toString(); - } - expect(text).toMatchInlineSnapshot(` - "{ - num: 1 - } - { - num: 2 - } - { - num: 3 - } - " - `); -}); - -test('zq with readable stream', async () => { - const input = Stream.Readable.from('1 2 3', { encoding: 'utf-8' }); - const objects = await zq({ query: '{num: this}', as: 'js', input }); - - expect(objects).toMatchInlineSnapshot(` - [ - { - "num": 1, - }, - { - "num": 2, - }, - { - "num": 3, - }, - ] - `); -}); - -test('zq with file', async () => { - const file = getPath('zillow.csv'); - const objects = await zq({ query: 'head 1', as: 'js', file }); - - expect(objects).toMatchInlineSnapshot(` - [ - { - "Bathrooms": 4, - "Bedrooms": 4, - "Broker agent": null, - "Broker name": "Coldwell Banker West", - "City": "Alpine", - "Country": "USA", - "Days on Zillow": null, - "Listing description": "Foreclosure", - "Living Area": 3653, - "Living Area Unit": "sqft", - "Lot size": null, - "Lot size unit": null, - "MLS ID": null, - "Price cut amount": null, - "Price cut date": null, - "Price per sqft": 273.75, - "Price was cut": "No", - "Property URL": "https://www.zillow.com/homedetails/1333-Ramblewood-Rd-Alpine-CA-91901/16903660_zpid/", - "Property price": 1000000, - "Property type": "OTHER", - "State": "CA", - "Street Address": "1333 Ramblewood Rd", - "Zip": 91901, - }, - ] - `); -}); - -test('zq with zjson objects', async () => { - const path = getPath('prs.json'); - const input = createReadStream(path); - - const data = await zq({ query: 'over this | head 10', as: 'zjson', input }); - - expect(data).toHaveLength(10); -}); - -test('zq with a file ', async () => { - const path = getPath('prs.json'); - - const data = await zq({ - query: 'over this | head 10', - as: 'zjson', - file: path, - }); - - expect(data).toHaveLength(10); -}); - test('zq with a bad zed ', async () => { const path = getPath('prs.json'); const promise = zq({ @@ -113,35 +16,3 @@ test('zq with a bad zed ', async () => { await expect(promise).rejects.toThrowError('error parsing Zed'); }); - -test('head 100 on guns ', async () => { - const path = getPath('background_checks.csv'); - const data = await zq({ - query: '* | head 100', - as: 'zjson', - input: createReadStream(path), - }); - expect(data).toHaveLength(100); -}); - -test('two files with different types', async () => { - const file1 = getPath('background_checks.csv'); - const file2 = getPath('prs.json'); - const data = await zq({ - query: 'count()', - as: 'js', - file: [file1, file2], - }); - expect(data).toEqual([16226]); -}); - -test('two files with different types as readable stream', async () => { - const file1 = getPath('background_checks.csv'); - const file2 = getPath('prs.json'); - const data = await zq({ - query: 'count()', - as: 'js', - file: [file1, file2], - }); - expect(data).toEqual([16226]); -});