Skip to content

Commit e537789

Browse files
committed
make it easier to run all integration tests from local data
1 parent c0fd2f9 commit e537789

File tree

5 files changed

+106
-45
lines changed

5 files changed

+106
-45
lines changed

js/bin/integration.js

Lines changed: 50 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
// specific language governing permissions and limitations
1818
// under the License.
1919

20+
var fs = require('fs');
21+
var glob = require('glob');
2022
var path = require('path');
2123
var gulp = require.resolve(path.join(`..`, `node_modules/gulp/bin/gulp.js`));
2224
var child_process = require(`child_process`);
@@ -29,12 +31,14 @@ var optionList = [
2931
{
3032
type: String,
3133
name: 'arrow', alias: 'a',
32-
description: 'The Arrow file to read/write'
34+
multiple: true, defaultValue: [],
35+
description: 'The Arrow file[s] to read/write'
3336
},
3437
{
3538
type: String,
3639
name: 'json', alias: 'j',
37-
description: 'The JSON file to read/write'
40+
multiple: true, defaultValue: [],
41+
description: 'The JSON file[s] to read/write'
3842
}
3943
];
4044

@@ -66,20 +70,60 @@ function print_usage() {
6670
process.exit(1);
6771
}
6872

69-
if (!argv.arrow || !argv.json || !argv.mode) {
73+
let jsonPaths = argv.json;
74+
let arrowPaths = argv.arrow;
75+
76+
if (!argv.mode) {
77+
return print_usage();
78+
}
79+
80+
let mode = argv.mode.toUpperCase();
81+
if (mode === 'VALIDATE' && !jsonPaths.length) {
82+
jsonPaths = glob.sync(path.resolve(__dirname, `../test/data/json/`, `*.json`));
83+
if (!arrowPaths.length) {
84+
[jsonPaths, arrowPaths] = jsonPaths.reduce(([jsonPaths, arrowPaths], jsonPath) => {
85+
const { name } = path.parse(jsonPath);
86+
for (const source of ['cpp', 'java']) {
87+
for (const format of ['file', 'stream']) {
88+
const arrowPath = path.resolve(__dirname, `../test/data/${source}/${format}/${name}.arrow`);
89+
if (fs.existsSync(arrowPath)) {
90+
jsonPaths.push(jsonPath);
91+
arrowPaths.push(arrowPath);
92+
console.log('-j', jsonPath, '-a', arrowPath, '\\');
93+
}
94+
}
95+
}
96+
return [jsonPaths, arrowPaths];
97+
}, [[], []]);
98+
}
99+
} else if (!jsonPaths.length) {
70100
return print_usage();
71101
}
72102

73-
switch (argv.mode.toUpperCase()) {
103+
switch (mode) {
74104
case 'VALIDATE':
105+
const args = [`test`, `-i`].concat(argv._unknown || []);
106+
jsonPaths.forEach((p, i) => {
107+
args.push('-j', p, '-a', arrowPaths[i]);
108+
});
75109
child_process.spawnSync(
76-
gulp,
77-
[`test`, `-i`].concat(process.argv.slice(2)),
110+
gulp, args,
78111
{
79112
cwd: path.resolve(__dirname, '..'),
80113
stdio: ['ignore', 'inherit', 'inherit']
81114
}
82115
);
116+
// for (let i = -1, n = jsonPaths.length; ++i < n;) {
117+
// const jsonPath = jsonPaths[i];
118+
// const arrowPath = arrowPaths[i];
119+
// child_process.spawnSync(
120+
// gulp, args.concat(['-j', jsonPath, '-a', arrowPath]),
121+
// {
122+
// cwd: path.resolve(__dirname, '..'),
123+
// stdio: ['ignore', 'inherit', 'inherit']
124+
// }
125+
// );
126+
// }
83127
break;
84128
default:
85129
print_usage();

js/gulp/argv.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,11 @@ const argv = require(`command-line-args`)([
2222
{ name: `target`, type: String, defaultValue: `` },
2323
{ name: `module`, type: String, defaultValue: `` },
2424
{ name: `coverage`, type: Boolean, defaultValue: false },
25-
{ name: `json_file`, alias: `j`, type: String, defaultValue: null },
26-
{ name: `arrow_file`, alias: `a`, type: String, defaultValue: null },
2725
{ name: `integration`, alias: `i`, type: Boolean, defaultValue: false },
2826
{ name: `targets`, alias: `t`, type: String, multiple: true, defaultValue: [] },
2927
{ name: `modules`, alias: `m`, type: String, multiple: true, defaultValue: [] },
30-
{ name: `sources`, alias: `s`, type: String, multiple: true, defaultValue: [`cpp`, `java`] },
31-
{ name: `formats`, alias: `f`, type: String, multiple: true, defaultValue: [`file`, `stream`] },
28+
{ name: `json_files`, alias: `j`, type: String, multiple: true, defaultValue: [] },
29+
{ name: `arrow_files`, alias: `a`, type: String, multiple: true, defaultValue: [] },
3230
], { partial: true });
3331

3432
const { targets, modules } = argv;

js/gulp/test-task.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,9 @@ const testTask = ((cache, execArgv, testOptions) => memoizeTask(cache, function
4848
opts.env = { ...opts.env,
4949
TEST_TARGET: target,
5050
TEST_MODULE: format,
51-
JSON_PATH: argv.json_file,
52-
ARROW_PATH: argv.arrow_file,
5351
TEST_TS_SOURCE: !!argv.coverage,
54-
TEST_SOURCES: JSON.stringify(Array.isArray(argv.sources) ? argv.sources : [argv.sources]),
55-
TEST_FORMATS: JSON.stringify(Array.isArray(argv.formats) ? argv.formats : [argv.formats]),
52+
JSON_PATHS: JSON.stringify(Array.isArray(argv.json_files) ? argv.json_files : [argv.json_files]),
53+
ARROW_PATHS: JSON.stringify(Array.isArray(argv.arrow_files) ? argv.arrow_files : [argv.arrow_files]),
5654
};
5755
return !debug ?
5856
child_process.spawn(jest, args, opts) :

js/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@
6262
"devDependencies": {
6363
"@std/esm": "0.19.7",
6464
"@types/flatbuffers": "1.6.5",
65-
"@types/glob": "5.0.34",
66-
"@types/jest": "22.0.1",
65+
"@types/glob": "5.0.35",
66+
"@types/jest": "22.1.0",
6767
"@types/node": "9.3.0",
6868
"ast-types": "0.10.1",
6969
"benchmark": "2.1.4",
@@ -78,9 +78,9 @@
7878
"gulp-rename": "1.2.2",
7979
"gulp-sourcemaps": "2.6.3",
8080
"gulp-transform-js-ast": "1.0.2",
81-
"gulp-typescript": "3.2.3",
81+
"gulp-typescript": "3.2.4",
8282
"ix": "2.3.4",
83-
"jest": "22.1.3",
83+
"jest": "22.1.4",
8484
"jest-environment-node-debug": "2.0.0",
8585
"json": "9.0.6",
8686
"lerna": "2.7.1",

js/test/integration/validate-tests.ts

Lines changed: 48 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -18,28 +18,41 @@
1818
import * as fs from 'fs';
1919
import * as path from 'path';
2020

21-
if (!process.env.JSON_PATH || !process.env.ARROW_PATH) {
22-
throw new Error('Integration tests need paths to both json and arrow files');
23-
}
21+
import Arrow from '../Arrow';
22+
import { zip } from 'ix/iterable/zip';
23+
import { toArray } from 'ix/iterable/toarray';
2424

25-
const jsonPath = path.resolve(process.env.JSON_PATH + '');
26-
const arrowPath = path.resolve(process.env.ARROW_PATH + '');
25+
/* tslint:disable */
26+
const { parse: bignumJSONParse } = require('json-bignum');
2727

28-
if (!fs.existsSync(jsonPath) || !fs.existsSync(arrowPath)) {
29-
throw new Error('Integration tests need both json and arrow files to exist');
30-
}
28+
const { Table, read } = Arrow;
3129

32-
/* tslint:disable */
33-
const { parse } = require('json-bignum');
30+
if (!process.env.JSON_PATHS || !process.env.ARROW_PATHS) {
31+
throw new Error('Integration tests need paths to both json and arrow files');
32+
}
3433

35-
const jsonData = parse(fs.readFileSync(jsonPath, 'utf8'));
36-
const arrowBuffers: Uint8Array[] = [fs.readFileSync(arrowPath)];
34+
function resolvePathArgs(paths: string) {
35+
let pathsArray = JSON.parse(paths) as string | string[];
36+
return (Array.isArray(pathsArray) ? pathsArray : [pathsArray])
37+
.map((p) => path.resolve(p))
38+
.map((p) => {
39+
if (fs.existsSync(p)) {
40+
return p;
41+
}
42+
console.warn(`Could not find file "${p}"`);
43+
return undefined;
44+
});
45+
}
3746

38-
import Arrow from '../Arrow';
39-
import { zip } from 'ix/iterable/zip';
40-
import { toArray } from 'ix/iterable/toarray';
47+
const getOrReadFileBuffer = ((cache: any) => function getFileBuffer(path: string, ...args: any[]) {
48+
return cache[path] || (cache[path] = fs.readFileSync(path, ...args));
49+
})({});
4150

42-
const { Table, read } = Arrow;
51+
const jsonAndArrowPaths = toArray(zip(
52+
resolvePathArgs(process.env.JSON_PATHS!),
53+
resolvePathArgs(process.env.ARROW_PATHS!)
54+
))
55+
.filter(([p1, p2]) => p1 !== undefined && p2 !== undefined) as [string, string][];
4356

4457
expect.extend({
4558
toEqualVector(v1: any, v2: any) {
@@ -66,7 +79,7 @@ expect.extend({
6679

6780
for (let i = -1, n = props.length; ++i < n;) {
6881
const prop = props[i];
69-
if (this.utils.stringify(v1[prop]) !== this.utils.stringify(v2[prop])) {
82+
if (`${v1[prop]}` !== `${v2[prop]}`) {
7083
propsFailures.push(`${prop}: ${format(v1[prop], v2[prop], ' !== ')}`);
7184
}
7285
}
@@ -98,35 +111,43 @@ expect.extend({
98111
});
99112

100113
describe(`Integration`, () => {
101-
testReaderIntegration();
102-
testTableFromBuffersIntegration();
114+
for (const [jsonFilePath, arrowFilePath] of jsonAndArrowPaths) {
115+
let { name, dir } = path.parse(arrowFilePath);
116+
dir = dir.split(path.sep).slice(-2).join(path.sep);
117+
const json = bignumJSONParse(getOrReadFileBuffer(jsonFilePath, 'utf8'));
118+
const arrowBuffer = getOrReadFileBuffer(arrowFilePath) as Uint8Array;
119+
describe(path.join(dir, name), () => {
120+
testReaderIntegration(json, arrowBuffer);
121+
testTableFromBuffersIntegration(json, arrowBuffer);
122+
});
123+
}
103124
});
104125

105-
function testReaderIntegration() {
106-
test(`json and arrow buffers report the same values`, () => {
107-
debugger;
126+
function testReaderIntegration(jsonData: any, arrowBuffer: Uint8Array) {
127+
test(`json and arrow record batches report the same values`, () => {
108128
expect.hasAssertions();
109129
const jsonRecordBatches = toArray(read(jsonData));
110-
const binaryRecordBatches = toArray(read(arrowBuffers));
130+
const binaryRecordBatches = toArray(read(arrowBuffer));
111131
for (const [jsonRecordBatch, binaryRecordBatch] of zip(jsonRecordBatches, binaryRecordBatches)) {
112132
expect(jsonRecordBatch.length).toEqual(binaryRecordBatch.length);
113133
expect(jsonRecordBatch.numCols).toEqual(binaryRecordBatch.numCols);
114134
for (let i = -1, n = jsonRecordBatch.numCols; ++i < n;) {
135+
(jsonRecordBatch.columns[i] as any).name = jsonRecordBatch.schema.fields[i].name;
115136
(expect(jsonRecordBatch.columns[i]) as any).toEqualVector(binaryRecordBatch.columns[i]);
116137
}
117138
}
118139
});
119140
}
120141

121-
function testTableFromBuffersIntegration() {
122-
test(`json and arrow buffers report the same values`, () => {
123-
debugger;
142+
function testTableFromBuffersIntegration(jsonData: any, arrowBuffer: Uint8Array) {
143+
test(`json and arrow tables report the same values`, () => {
124144
expect.hasAssertions();
125145
const jsonTable = Table.from(jsonData);
126-
const binaryTable = Table.from(arrowBuffers);
146+
const binaryTable = Table.from(arrowBuffer);
127147
expect(jsonTable.length).toEqual(binaryTable.length);
128148
expect(jsonTable.numCols).toEqual(binaryTable.numCols);
129149
for (let i = -1, n = jsonTable.numCols; ++i < n;) {
150+
(jsonTable.columns[i] as any).name = jsonTable.schema.fields[i].name;
130151
(expect(jsonTable.columns[i]) as any).toEqualVector(binaryTable.columns[i]);
131152
}
132153
});

0 commit comments

Comments
 (0)