Skip to content

Commit bfd6943

Browse files
authored
Node testing setup (#34)
1 parent 3b7cbc6 commit bfd6943

22 files changed

+969
-15
lines changed

.github/workflows/test.yml

+21
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,27 @@ jobs:
2727
# - run: cargo check --no-default-features --features "console_error_panic_hook wee_alloc"
2828
# - run: cargo check --target wasm32-unknown-unknown --no-default-features --features "console_error_panic_hook wee_alloc"
2929

30+
node-test:
31+
runs-on: ubuntu-latest
32+
steps:
33+
- uses: actions/checkout@v2
34+
35+
- name: Install
36+
run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
37+
38+
- uses: actions/setup-node@v2
39+
with:
40+
node-version: "16"
41+
42+
- name: Build bundle
43+
run: bash ./scripts/build.sh
44+
45+
- name: Install dev dependencies
46+
run: yarn
47+
48+
- name: Run Node tests
49+
run: yarn test
50+
3051
fmt:
3152
name: fmt
3253
runs-on: ubuntu-latest

data/data.arrow

-978 Bytes
Binary file not shown.

data/not_work.parquet

-543 Bytes
Binary file not shown.

data/works.parquet

-511 Bytes
Binary file not shown.

package.json

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"scripts": {
3+
"test": "ts-node node_modules/tape/bin/tape ./tests/js/index.ts"
4+
},
5+
"devDependencies": {
6+
"@types/node": "^17.0.21",
7+
"@types/tape": "^4.13.2",
8+
"apache-arrow": "^7.0.0",
9+
"tape": "^5.5.2",
10+
"ts-node": "^10.7.0",
11+
"typescript": "^4.6.2"
12+
}
13+
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

data/generate_data.py tests/data/generate_data.py

+1-15
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import pyarrow.feather as feather
33
import pyarrow.parquet as pq
44

5-
compressions = ["SNAPPY", "GZIP", "BROTLI", "LZ4", "ZSTD", 'NONE']
5+
compressions = ["SNAPPY", "GZIP", "BROTLI", "LZ4", "ZSTD", "NONE"]
66

77

88
def create_data():
@@ -35,19 +35,5 @@ def main():
3535
write_data(table)
3636

3737

38-
def debug():
39-
"""Create debug data"""
40-
works = pa.table({
41-
"uint8": pa.array([1, 2, 3, 4], type=pa.uint8()),
42-
})
43-
pq.write_table(works, 'works.parquet', compression='NONE')
44-
45-
not_work = pa.table({
46-
"int8": pa.array([0, 0, 0, 0], type=pa.int8()),
47-
})
48-
pq.write_table(not_work, 'not_work.parquet', compression='NONE')
49-
50-
5138
if __name__ == "__main__":
5239
main()
53-
debug()

tests/js/arrow1.ts

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import * as test from "tape";
2+
import * as wasm from "../../pkg/node";
3+
import { readFileSync } from "fs";
4+
import { tableFromIPC, tableToIPC, Table } from "apache-arrow";
5+
6+
// Path from repo root
7+
const dataDir = "tests/data";
8+
const testFiles = [
9+
"1-partition-brotli.parquet",
10+
"1-partition-gzip.parquet",
11+
// "1-partition-lz4.parquet",
12+
"1-partition-none.parquet",
13+
"1-partition-snappy.parquet",
14+
// "1-partition-zstd.parquet",
15+
"2-partition-brotli.parquet",
16+
"2-partition-gzip.parquet",
17+
// "2-partition-lz4.parquet",
18+
"2-partition-none.parquet",
19+
"2-partition-snappy.parquet",
20+
// "2-partition-zstd.parquet",
21+
];
22+
23+
function testArrow(t: test.Test, table: Table) {
24+
t.equals(table.numRows, 4, "correct number of rows");
25+
t.deepEquals(
26+
table.schema.fields.map((f) => f.name),
27+
["str", "uint8", "int32", "bool"],
28+
"correct column names"
29+
);
30+
}
31+
32+
test("read file", async (t) => {
33+
for (const testFile of testFiles) {
34+
const dataPath = `${dataDir}/${testFile}`;
35+
const buffer = readFileSync(dataPath);
36+
const arr = new Uint8Array(buffer);
37+
const table = tableFromIPC(wasm.readParquet(arr));
38+
testArrow(t, table);
39+
}
40+
41+
t.end();
42+
});
43+
44+
test("write and read file", async (t) => {
45+
const dataPath = `${dataDir}/1-partition-brotli.parquet`;
46+
const buffer = readFileSync(dataPath);
47+
const arr = new Uint8Array(buffer);
48+
const initialTable = tableFromIPC(wasm.readParquet(arr));
49+
50+
const writerProperties = new wasm.WriterPropertiesBuilder().build();
51+
52+
const parquetBuffer = wasm.writeParquet(
53+
tableToIPC(initialTable, "stream"),
54+
writerProperties
55+
);
56+
const table = tableFromIPC(wasm.readParquet(parquetBuffer));
57+
58+
testArrow(t, table);
59+
t.end();
60+
});

tests/js/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import './arrow1';

tsconfig.json

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"compilerOptions": {
3+
"module": "commonjs",
4+
"moduleResolution": "node"
5+
},
6+
"include": [
7+
"tests/**/*"
8+
],
9+
"exclude": [
10+
"node_modules"
11+
]
12+
}

0 commit comments

Comments
 (0)