mirror of
https://github.com/dolthub/dolt.git
synced 2026-05-12 19:39:32 -05:00
Jest (#3145)
This changes to use Jest. Benefits of jest is parallel tests and jest can run the minimal set of tests that are affected by a change (by looking at dependencies). The main work was to disentangle our cyclic dependencies. To do this I had to remove some runtime assertions in encode value as well as expose the values of a struct without going through a struct mirror.
This commit is contained in:
@@ -3,3 +3,4 @@ dist
|
||||
generated-docs
|
||||
.nyc_output
|
||||
coverage.lcov
|
||||
coverage
|
||||
|
||||
+10
-5
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "@attic/noms",
|
||||
"license": "Apache-2.0",
|
||||
"version": "69.6.0",
|
||||
"version": "69.6.1",
|
||||
"description": "Noms JS SDK",
|
||||
"repository": "https://github.com/attic-labs/noms/tree/master/js/noms",
|
||||
"main": "dist/commonjs/noms.js",
|
||||
@@ -27,6 +27,7 @@
|
||||
"flow-bin": "^0.38.0",
|
||||
"flow-copy-source": "^1.1.0",
|
||||
"fs-extra": "^2.0.0",
|
||||
"jest": "^18.1.0",
|
||||
"mocha": "^3.2.0",
|
||||
"mock-require": "^2.0.1",
|
||||
"nyc": "^10.1.2"
|
||||
@@ -34,10 +35,8 @@
|
||||
"scripts": {
|
||||
"lint": "eslint src/",
|
||||
"flow": "flow src/",
|
||||
"pretest": "yarn run lint && yarn run flow",
|
||||
"ts": "mocha --ui tdd --timeout=4000 --reporter dot --slow=50 --invert --grep='LONG:' --compilers js:babel-core/register src/*-test.js",
|
||||
"test-no-cov": "mocha --ui tdd --timeout=30000 --reporter dot --compilers js:babel-core/register src/*-test.js",
|
||||
"test": "nyc yarn run test-no-cov && nyc report --reporter=text-lcov > coverage.lcov",
|
||||
"jest": "jest",
|
||||
"test": "yarn run lint && yarn run flow && jest --coverage",
|
||||
"prepublish": "rm -rf dist/ && yarn run compile && yarn run flow-copy-source",
|
||||
"compile": "yarn run compile-to-commonjs",
|
||||
"compile-to-commonjs": "BABEL_ENV=production babel -d dist/commonjs src/ > /dev/null",
|
||||
@@ -52,5 +51,11 @@
|
||||
"./dist/commonjs/fetch.js": "./dist/commonjs/browser/fetch.js",
|
||||
"./src/put-cache.js": "./src/browser/put-cache.js",
|
||||
"./dist/commonjs/put-cache.js": "./dist/commonjs/browser/put-cache.js"
|
||||
},
|
||||
"jest": {
|
||||
"testRegex": ".+-test\\.js$",
|
||||
"testPathIgnorePatterns": [
|
||||
"/dist/"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
// @flow
|
||||
|
||||
import {assert} from 'chai';
|
||||
import {suite, test} from 'mocha';
|
||||
import {suite, test} from './jest.js';
|
||||
import {equals} from './compare.js';
|
||||
|
||||
import {invariant, notNull} from './assert.js';
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
// @flow
|
||||
|
||||
import {suite, test} from 'mocha';
|
||||
import {suite, test} from './jest.js';
|
||||
import {assert} from 'chai';
|
||||
import {invariant, notNull} from './assert.js';
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ import List from './list.js';
|
||||
import Map from './map.js';
|
||||
import Set from './set.js';
|
||||
import {newStruct} from './struct.js';
|
||||
import {suite, test} from 'mocha';
|
||||
import {suite, test} from './jest.js';
|
||||
import assertSubtype, {isSubtype} from './assert-type.js';
|
||||
import type {Type} from './type.js';
|
||||
import {
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
import {encode, decode} from './base32.js';
|
||||
import {assert} from 'chai';
|
||||
import {alloc} from './bytes.js';
|
||||
import {suite, test} from 'mocha';
|
||||
import {suite, test} from './jest.js';
|
||||
|
||||
suite('base32', () => {
|
||||
test('encode', () => {
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
// Copyright 2016 Attic Labs, Inc. All rights reserved.
|
||||
// Licensed under the Apache License, version 2.0:
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
// @flow
|
||||
|
||||
import * as Bytes from './bytes.js';
|
||||
import Hash, {byteLength as hashByteLength} from './hash.js';
|
||||
import type TypeCache from './type-cache.js';
|
||||
import {BinaryReader} from './binary-rw.js';
|
||||
|
||||
export default class BinaryNomsReader extends BinaryReader {
|
||||
constructor(buff: Uint8Array) {
|
||||
super(buff);
|
||||
}
|
||||
|
||||
readIdent(tc: TypeCache): number {
|
||||
const str = this.readString(); // TODO: Figure out how to do this without allocating.
|
||||
let id = tc.identTable.entries.get(str);
|
||||
if (id === undefined) {
|
||||
id = tc.identTable.getId(str);
|
||||
}
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
readHash(): Hash {
|
||||
// Make a copy of the data.
|
||||
const digest = Bytes.slice(this.buff, this.offset, this.offset + hashByteLength);
|
||||
this.offset += hashByteLength;
|
||||
return new Hash(digest);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
// Copyright 2016 Attic Labs, Inc. All rights reserved.
|
||||
// Licensed under the Apache License, version 2.0:
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
// @flow
|
||||
|
||||
import * as Bytes from './bytes.js';
|
||||
import Hash, {byteLength as hashByteLength} from './hash.js';
|
||||
import ValueEncoder from './value-encoder.js';
|
||||
import type {Type} from './type.js';
|
||||
import {notNull} from './assert.js';
|
||||
import {BinaryWriter} from './binary-rw.js';
|
||||
|
||||
function ensureTypeSerialization(t: Type<any>) {
|
||||
if (!t.serialization) {
|
||||
const w = new BinaryNomsWriter();
|
||||
const enc = new ValueEncoder(w, null);
|
||||
enc.writeType(t, []);
|
||||
t.serialization = w.data;
|
||||
}
|
||||
}
|
||||
|
||||
export default class BinaryNomsWriter extends BinaryWriter {
|
||||
constructor() {
|
||||
super();
|
||||
}
|
||||
|
||||
writeHash(h: Hash): void {
|
||||
this.ensureCapacity(hashByteLength);
|
||||
Bytes.copy(h.digest, this.buff, this.offset);
|
||||
this.offset += hashByteLength;
|
||||
}
|
||||
|
||||
appendType(t: Type<any>): void {
|
||||
// Note: The JS & Go impls differ here. The Go impl eagerly serializes types as they are
|
||||
// constructed. The JS does it lazily so as to avoid cyclic package dependencies.
|
||||
ensureTypeSerialization(t);
|
||||
const data = notNull(t.serialization);
|
||||
const size = data.byteLength;
|
||||
this.ensureCapacity(size);
|
||||
|
||||
Bytes.copy(data, this.buff, this.offset);
|
||||
this.offset += size;
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,7 @@
|
||||
import {blobType, makeRefType} from './type.js';
|
||||
import {assert} from 'chai';
|
||||
import Blob, {BlobReader, BlobWriter} from './blob.js';
|
||||
import {suite, suiteSetup, suiteTeardown, test, setup, teardown} from 'mocha';
|
||||
import {suite, suiteSetup, suiteTeardown, test, setup, teardown} from './jest.js';
|
||||
import {
|
||||
assertChunkCountAndType,
|
||||
assertValueHash,
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
// @flow
|
||||
|
||||
import {suite, test} from 'mocha';
|
||||
import {suite, test} from './jest.js';
|
||||
import {assert} from 'chai';
|
||||
import BuzHash from './buzhash.js';
|
||||
import * as Bytes from './bytes.js';
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
// @flow
|
||||
|
||||
import {assert} from 'chai';
|
||||
import {suite, test} from 'mocha';
|
||||
import {suite, test} from './jest.js';
|
||||
|
||||
import * as NodeBytes from './bytes.js';
|
||||
import * as BrowserBytes from './browser/bytes.js';
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
// @flow
|
||||
|
||||
import {suite, test} from 'mocha';
|
||||
import {suite, test} from './jest.js';
|
||||
import {assert} from 'chai';
|
||||
import Chunk from './chunk.js';
|
||||
import type Hash from './hash.js';
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
// @flow
|
||||
|
||||
import {suite, test} from 'mocha';
|
||||
import {suite, test} from './jest.js';
|
||||
import {assert} from 'chai';
|
||||
import Chunk from './chunk.js';
|
||||
import Hash from './hash.js';
|
||||
|
||||
@@ -1,130 +0,0 @@
|
||||
// Copyright 2016 Attic Labs, Inc. All rights reserved.
|
||||
// Licensed under the Apache License, version 2.0:
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
// @flow
|
||||
|
||||
import * as Bytes from './bytes.js';
|
||||
import Chunk from './chunk.js';
|
||||
import Hash, {byteLength as hashByteLength} from './hash.js';
|
||||
import ValueDecoder from './value-decoder.js';
|
||||
import ValueEncoder from './value-encoder.js';
|
||||
import type Value from './value.js';
|
||||
import type {Type} from './type.js';
|
||||
import type {ValueReader, ValueWriter} from './value-store.js';
|
||||
import {default as TypeCache, staticTypeCache} from './type-cache.js';
|
||||
import {notNull} from './assert.js';
|
||||
import {setEncodeValue} from './get-hash.js';
|
||||
import {setHash, ValueBase} from './value.js';
|
||||
import {BinaryReader, BinaryWriter} from './binary-rw.js';
|
||||
|
||||
export function encodeValue(v: Value, vw: ?ValueWriter): Chunk {
|
||||
const w = new BinaryNomsWriter();
|
||||
const enc = new ValueEncoder(w, vw);
|
||||
enc.writeValue(v);
|
||||
const chunk = new Chunk(w.data);
|
||||
if (v instanceof ValueBase) {
|
||||
setHash(v, chunk.hash);
|
||||
}
|
||||
|
||||
return chunk;
|
||||
}
|
||||
|
||||
setEncodeValue(encodeValue);
|
||||
|
||||
export function decodeValue(chunk: Chunk, vr: ValueReader): Value {
|
||||
const data = chunk.data;
|
||||
const br = new BinaryNomsReader(data);
|
||||
const dec = new ValueDecoder(br, vr, staticTypeCache);
|
||||
const v = dec.readValue();
|
||||
if (br.pos() !== data.byteLength) {
|
||||
throw new Error('Invalid chunk data: not all bytes consumed');
|
||||
}
|
||||
if (v instanceof ValueBase) {
|
||||
setHash(v, chunk.hash);
|
||||
}
|
||||
|
||||
return v;
|
||||
}
|
||||
|
||||
function ensureTypeSerialization(t: Type<any>) {
|
||||
if (!t.serialization) {
|
||||
const w = new BinaryNomsWriter();
|
||||
const enc = new ValueEncoder(w, null);
|
||||
enc.writeType(t, []);
|
||||
t.serialization = w.data;
|
||||
}
|
||||
}
|
||||
|
||||
export interface NomsReader {
|
||||
pos(): number;
|
||||
seek(pos: number): void;
|
||||
readBytes(): Uint8Array;
|
||||
readUint8(): number;
|
||||
readUint32(): number;
|
||||
readUint64(): number;
|
||||
readNumber(): number;
|
||||
readBool(): boolean;
|
||||
readString(): string;
|
||||
readIdent(tc: TypeCache): number;
|
||||
readHash(): Hash;
|
||||
}
|
||||
|
||||
export interface NomsWriter {
|
||||
writeBytes(v: Uint8Array): void;
|
||||
writeUint8(v: number): void;
|
||||
writeUint32(v: number): void;
|
||||
writeUint64(v: number): void;
|
||||
writeNumber(v: number): void;
|
||||
writeBool(v: boolean): void;
|
||||
writeString(v: string): void;
|
||||
writeHash(h: Hash): void;
|
||||
appendType(t: Type<any>): void;
|
||||
}
|
||||
|
||||
export class BinaryNomsReader extends BinaryReader {
|
||||
constructor(buff: Uint8Array) {
|
||||
super(buff);
|
||||
}
|
||||
|
||||
readIdent(tc: TypeCache): number {
|
||||
const str = this.readString(); // TODO: Figure out how to do this without allocating.
|
||||
let id = tc.identTable.entries.get(str);
|
||||
if (id === undefined) {
|
||||
id = tc.identTable.getId(str);
|
||||
}
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
readHash(): Hash {
|
||||
// Make a copy of the data.
|
||||
const digest = Bytes.slice(this.buff, this.offset, this.offset + hashByteLength);
|
||||
this.offset += hashByteLength;
|
||||
return new Hash(digest);
|
||||
}
|
||||
}
|
||||
|
||||
export class BinaryNomsWriter extends BinaryWriter {
|
||||
constructor() {
|
||||
super();
|
||||
}
|
||||
|
||||
writeHash(h: Hash): void {
|
||||
this.ensureCapacity(hashByteLength);
|
||||
Bytes.copy(h.digest, this.buff, this.offset);
|
||||
this.offset += hashByteLength;
|
||||
}
|
||||
|
||||
appendType(t: Type<any>): void {
|
||||
// Note: The JS & Go impls differ here. The Go impl eagerly serializes types as they are
|
||||
// constructed. The JS does it lazily so as to avoid cyclic package dependencies.
|
||||
ensureTypeSerialization(t);
|
||||
const data = notNull(t.serialization);
|
||||
const size = data.byteLength;
|
||||
this.ensureCapacity(size);
|
||||
|
||||
Bytes.copy(data, this.buff, this.offset);
|
||||
this.offset += size;
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
// @flow
|
||||
|
||||
import {suite, test} from 'mocha';
|
||||
import {suite, test} from './jest.js';
|
||||
import {assert} from 'chai';
|
||||
import {equals} from './compare.js';
|
||||
import {
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
// @flow
|
||||
|
||||
import {suite, test} from 'mocha';
|
||||
import {suite, test} from './jest.js';
|
||||
import {assert} from 'chai';
|
||||
import {equals, compare} from './compare.js';
|
||||
import {
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
// @flow
|
||||
|
||||
import {suite, test} from 'mocha';
|
||||
import {suite, test} from './jest.js';
|
||||
import makeRemoteBatchStoreFake from './remote-batch-store-fake.js';
|
||||
import {TestingDelegate} from './remote-batch-store-fake.js';
|
||||
import RemoteBatchStore from './remote-batch-store.js';
|
||||
@@ -15,7 +15,7 @@ import Database from './database.js';
|
||||
import {notNull} from './assert.js';
|
||||
import List from './list.js';
|
||||
import Struct, {newStruct} from './struct.js';
|
||||
import {encodeValue} from './codec.js';
|
||||
import encodeValue from './encode-value.js';
|
||||
import NomsSet from './set.js'; // namespace collision with JS Set
|
||||
import {invariant} from './assert.js';
|
||||
import {Kind} from './noms-kind.js';
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
// @flow
|
||||
|
||||
import {suite, test} from 'mocha';
|
||||
import {suite, test} from './jest.js';
|
||||
import makeRemoteBatchStoreFake from './remote-batch-store-fake.js';
|
||||
import {assert} from 'chai';
|
||||
import Database from './database.js';
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
// Copyright 2016 Attic Labs, Inc. All rights reserved.
|
||||
// Licensed under the Apache License, version 2.0:
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
// @flow
|
||||
|
||||
import type Chunk from './chunk.js';
|
||||
import ValueDecoder from './value-decoder.js';
|
||||
import type Value from './value.js';
|
||||
import type {ValueReader} from './value-store.js';
|
||||
import {staticTypeCache} from './type-cache.js';
|
||||
import {setHash, ValueBase} from './value.js';
|
||||
import BinaryNomsReader from './binary-noms-reader.js';
|
||||
|
||||
export default function decodeValue(chunk: Chunk, vr: ValueReader): Value {
|
||||
const data = chunk.data;
|
||||
const br = new BinaryNomsReader(data);
|
||||
const dec = new ValueDecoder(br, vr, staticTypeCache);
|
||||
const v = dec.readValue();
|
||||
if (br.pos() !== data.byteLength) {
|
||||
throw new Error('Invalid chunk data: not all bytes consumed');
|
||||
}
|
||||
if (v instanceof ValueBase) {
|
||||
setHash(v, chunk.hash);
|
||||
}
|
||||
|
||||
return v;
|
||||
}
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
// @flow
|
||||
|
||||
import {suite, test} from 'mocha';
|
||||
import {suite, test} from './jest.js';
|
||||
import type {Splice} from './edit-distance.js';
|
||||
import {assert} from 'chai';
|
||||
import {DEFAULT_MAX_SPLICE_MATRIX_SIZE, calcSplices} from './edit-distance.js';
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
// @flow
|
||||
|
||||
import {assert} from 'chai';
|
||||
import {suite, test} from 'mocha';
|
||||
import {suite, test} from './jest.js';
|
||||
|
||||
import {invariant, notNull} from './assert.js';
|
||||
import {TypeWriter} from './encode-human-readable.js';
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
// Copyright 2016 Attic Labs, Inc. All rights reserved.
|
||||
// Licensed under the Apache License, version 2.0:
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
// @flow
|
||||
|
||||
import Chunk from './chunk.js';
|
||||
import ValueEncoder from './value-encoder.js';
|
||||
import type Value from './value.js';
|
||||
import type {ValueWriter} from './value-store.js';
|
||||
import {setHash, ValueBase} from './value.js';
|
||||
import BinaryNomsWriter from './binary-noms-writer.js';
|
||||
|
||||
export default function encodeValue(v: Value, vw: ?ValueWriter): Chunk {
|
||||
const w = new BinaryNomsWriter();
|
||||
const enc = new ValueEncoder(w, vw);
|
||||
enc.writeValue(v);
|
||||
const chunk = new Chunk(w.data);
|
||||
if (v instanceof ValueBase) {
|
||||
setHash(v, chunk.hash);
|
||||
}
|
||||
|
||||
return chunk;
|
||||
}
|
||||
@@ -5,7 +5,7 @@
|
||||
/* eslint-disable max-len */
|
||||
// @flow
|
||||
|
||||
import {suite, test} from 'mocha';
|
||||
import {suite, test} from './jest.js';
|
||||
import {assert} from 'chai';
|
||||
|
||||
import Blob from './blob.js';
|
||||
@@ -22,7 +22,8 @@ import type Value from './value.js';
|
||||
import {ValueBase} from './value.js';
|
||||
import {Kind} from './noms-kind.js';
|
||||
import {TestDatabase} from './test-util.js';
|
||||
import {encodeValue, decodeValue} from './codec.js';
|
||||
import encodeValue from './encode-value.js';
|
||||
import decodeValue from './decode-value.js';
|
||||
import {equals} from './compare.js';
|
||||
import {invariant, notNull} from './assert.js';
|
||||
import {newStruct, newStructWithType} from './struct.js';
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
// @flow
|
||||
|
||||
import {assert} from 'chai';
|
||||
import {suite, test, setup, teardown} from 'mocha';
|
||||
import {suite, test, setup, teardown} from './jest.js';
|
||||
import mock from 'mock-require';
|
||||
|
||||
suite('fetch', () => {
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
import Hash from './hash.js';
|
||||
import {assert} from 'chai';
|
||||
import {ensureHash} from './get-hash.js';
|
||||
import {suite, test} from 'mocha';
|
||||
import {suite, test} from './jest.js';
|
||||
|
||||
suite('get hash', () => {
|
||||
test('ensureHash', () => {
|
||||
|
||||
@@ -4,16 +4,12 @@
|
||||
|
||||
// @flow
|
||||
|
||||
import type Chunk from './chunk.js';
|
||||
import type Hash from './hash.js';
|
||||
import type {ValueWriter} from './value-store.js';
|
||||
import {notNull} from './assert.js';
|
||||
import type Value from './value.js';
|
||||
import {getTypeOfValue} from './type.js';
|
||||
import {ValueBase} from './value.js';
|
||||
|
||||
type encodeFn = (v: Value, vw: ?ValueWriter) => Chunk;
|
||||
let encodeValue: ?encodeFn = null;
|
||||
import encodeValue from './encode-value.js';
|
||||
|
||||
/**
|
||||
* Returns the hash of a Noms value. All Noms values have a unique hash and if two values have the
|
||||
@@ -38,7 +34,3 @@ export function ensureHash(h: ?Hash, v: Value): Hash {
|
||||
|
||||
return getHash(v);
|
||||
}
|
||||
|
||||
export function setEncodeValue(encode: encodeFn) {
|
||||
encodeValue = encode;
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ import Hash, {emptyHash} from './hash.js';
|
||||
import {assert} from 'chai';
|
||||
import * as Bytes from './bytes.js';
|
||||
import {notNull} from './assert.js';
|
||||
import {suite, test} from 'mocha';
|
||||
import {suite, test} from './jest.js';
|
||||
|
||||
suite('Hash', () => {
|
||||
test('parse', () => {
|
||||
|
||||
@@ -4,16 +4,17 @@
|
||||
|
||||
// @flow
|
||||
|
||||
import {suite, test, setup, teardown} from 'mocha';
|
||||
import jest, {suite, test, setup, teardown} from './jest.js';
|
||||
import {assert} from 'chai';
|
||||
import Hash from './hash.js';
|
||||
import {emptyHash} from './hash.js';
|
||||
import HttpBatchStore from './http-batch-store.js';
|
||||
import mock from 'mock-require';
|
||||
import {invariant} from './assert.js';
|
||||
|
||||
|
||||
suite('HttpBatchStore', () => {
|
||||
setup(() => {
|
||||
mock('http', {
|
||||
jest.mock('http', () => ({
|
||||
request(options, cb) {
|
||||
cb({statusCode: 409});
|
||||
return {
|
||||
@@ -22,11 +23,11 @@ suite('HttpBatchStore', () => {
|
||||
setTimeout() {},
|
||||
};
|
||||
},
|
||||
});
|
||||
}));
|
||||
});
|
||||
|
||||
teardown(() => {
|
||||
mock.stopAll();
|
||||
jest.resetModules();
|
||||
});
|
||||
|
||||
test('endpoints', async () => {
|
||||
@@ -58,11 +59,11 @@ suite('HttpBatchStore', () => {
|
||||
});
|
||||
|
||||
test('updateRoot conflict', async () => {
|
||||
mock.reRequire('./fetch.js');
|
||||
const HttpBatchStore = mock.reRequire('./http-batch-store.js').default;
|
||||
const HttpBatchStore = require('./http-batch-store.js').default;
|
||||
const store = new HttpBatchStore('http://nowhere.com');
|
||||
|
||||
assert.isFalse(
|
||||
await store.updateRoot(Hash.parse('00001111000011110000111100001111'), emptyHash));
|
||||
const h = Hash.parse('00001111000011110000111100001111');
|
||||
invariant(h);
|
||||
assert.isFalse(await store.updateRoot(h, emptyHash));
|
||||
});
|
||||
});
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
import HttpError from './http-error.js';
|
||||
import {assert} from 'chai';
|
||||
import {suite, test} from 'mocha';
|
||||
import {suite, test} from './jest.js';
|
||||
|
||||
suite('http-error', () => {
|
||||
test('prototype', () => {
|
||||
|
||||
@@ -17,6 +17,8 @@ export async function newCursorAtIndex(sequence: Sequence<any>, idx: number,
|
||||
while (sequence) {
|
||||
cursor = new IndexedSequenceCursor(cursor, sequence, 0, readAhead);
|
||||
idx -= cursor.advanceToOffset(idx);
|
||||
// TODO: The Sequence type needs to be cleaned up.
|
||||
// $FlowIssue: xxx
|
||||
sequence = await cursor.getChildSequence();
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
// Copyright 2016 Attic Labs, Inc. All rights reserved.
|
||||
// Licensed under the Apache License, version 2.0:
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
// @flow
|
||||
|
||||
// Tell flow about these. When running the tests these are globals.
|
||||
declare var afterAll;
|
||||
declare var afterEach;
|
||||
declare var beforeAll;
|
||||
declare var beforeEach;
|
||||
declare var describe;
|
||||
declare var it;
|
||||
declare var jest;
|
||||
|
||||
export {
|
||||
afterAll as suiteTeardown,
|
||||
afterEach as teardown,
|
||||
beforeAll as suiteSetup,
|
||||
beforeEach as setup,
|
||||
describe as suite,
|
||||
it as test,
|
||||
jest as default,
|
||||
};
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
// @flow
|
||||
|
||||
import {suite, test} from 'mocha';
|
||||
import {suite, test} from './jest.js';
|
||||
import {assert} from 'chai';
|
||||
|
||||
import jsonToNoms from './json-convert.js';
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
// @flow
|
||||
|
||||
import {assert} from 'chai';
|
||||
import {suite, setup, teardown, test} from 'mocha';
|
||||
import {suite, setup, teardown, test} from './jest.js';
|
||||
|
||||
import List, {ListWriter, ListLeafSequence, newListLeafSequence} from './list.js';
|
||||
import Ref from './ref.js';
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
// @flow
|
||||
|
||||
import {assert} from 'chai';
|
||||
import {suite, setup, teardown, test} from 'mocha';
|
||||
import {suite, setup, teardown, test} from './jest.js';
|
||||
|
||||
import Blob from './blob.js';
|
||||
import Ref from './ref.js';
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
// @flow
|
||||
|
||||
import {assert} from 'chai';
|
||||
import {suite, test} from 'mocha';
|
||||
import {suite, test} from './jest.js';
|
||||
import Chunk from './chunk.js';
|
||||
import MemoryStore from './memory-store.js';
|
||||
import Hash from './hash.js';
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
// @flow
|
||||
|
||||
import {assert} from 'chai';
|
||||
import {suite, test} from 'mocha';
|
||||
import {suite, test} from './jest.js';
|
||||
|
||||
import List from './list.js';
|
||||
import {OrderedKey} from './sequence.js';
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
// Copyright 2016 Attic Labs, Inc. All rights reserved.
|
||||
// Licensed under the Apache License, version 2.0:
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
// @flow
|
||||
|
||||
import type Hash from './hash.js';
|
||||
import type TypeCache from './type-cache.js';
|
||||
|
||||
export interface NomsReader {
|
||||
pos(): number;
|
||||
seek(pos: number): void;
|
||||
readBytes(): Uint8Array;
|
||||
readUint8(): number;
|
||||
readUint32(): number;
|
||||
readUint64(): number;
|
||||
readNumber(): number;
|
||||
readBool(): boolean;
|
||||
readString(): string;
|
||||
readIdent(tc: TypeCache): number;
|
||||
readHash(): Hash;
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
// Copyright 2016 Attic Labs, Inc. All rights reserved.
|
||||
// Licensed under the Apache License, version 2.0:
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
// @flow
|
||||
|
||||
import type Hash from './hash.js';
|
||||
import type {Type} from './type.js';
|
||||
|
||||
export interface NomsWriter {
|
||||
writeBytes(v: Uint8Array): void;
|
||||
writeUint8(v: number): void;
|
||||
writeUint32(v: number): void;
|
||||
writeUint64(v: number): void;
|
||||
writeNumber(v: number): void;
|
||||
writeBool(v: boolean): void;
|
||||
writeString(v: string): void;
|
||||
writeHash(h: Hash): void;
|
||||
appendType(t: Type<any>): void;
|
||||
}
|
||||
+2
-2
@@ -11,7 +11,7 @@ export {default as Commit} from './commit.js';
|
||||
export {default as Database} from './database.js';
|
||||
export {default as Dataset} from './dataset.js';
|
||||
export {default as Blob, BlobReader, BlobWriter} from './blob.js';
|
||||
export {decodeValue} from './codec.js';
|
||||
export {default as decodeValue} from './decode-value.js';
|
||||
export {default as Chunk} from './chunk.js';
|
||||
export {getHashOfValue} from './get-hash.js';
|
||||
export {BatchStoreAdaptor} from './batch-store.js';
|
||||
@@ -30,7 +30,7 @@ export {
|
||||
createStructClass,
|
||||
escapeStructField,
|
||||
} from './struct.js';
|
||||
export {encodeValue} from './codec.js';
|
||||
export {default as encodeValue} from './encode-value.js';
|
||||
export {invariant, notNull} from './assert.js';
|
||||
export {isPrimitiveKind, Kind, kindToString} from './noms-kind.js';
|
||||
export {default as List, ListWriter, ListLeafSequence} from './list.js';
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
// @flow
|
||||
|
||||
import {suite, suiteSetup, suiteTeardown, test} from 'mocha';
|
||||
import {suite, suiteSetup, suiteTeardown, test} from './jest.js';
|
||||
import {assert} from 'chai';
|
||||
import {OrderedKey} from './sequence.js';
|
||||
import {MetaTuple, newSetMetaSequence} from './meta-sequence.js';
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
// @flow
|
||||
|
||||
import {assert} from 'chai';
|
||||
import {suite, test} from 'mocha';
|
||||
import {suite, test} from './jest.js';
|
||||
import {equals} from './compare.js';
|
||||
|
||||
import {getHash} from './get-hash.js';
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
// @flow
|
||||
|
||||
import {suite, test} from 'mocha';
|
||||
import {suite, test} from './jest.js';
|
||||
import {assert} from 'chai';
|
||||
import {notNull} from './assert.js';
|
||||
import NodeOrderedPutCache from './put-cache.js';
|
||||
|
||||
@@ -4,10 +4,10 @@
|
||||
|
||||
// @flow
|
||||
|
||||
import {suite, test} from 'mocha';
|
||||
import {suite, test} from './jest.js';
|
||||
import {assert} from 'chai';
|
||||
import makeRemoteBatchStoreFake from './remote-batch-store-fake.js';
|
||||
import {encodeValue} from './codec.js';
|
||||
import encodeValue from './encode-value.js';
|
||||
|
||||
suite('BatchStore', () => {
|
||||
test('get after schedulePut works immediately', async () => {
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
// @flow
|
||||
|
||||
import {suite, test} from 'mocha';
|
||||
import {suite, test} from './jest.js';
|
||||
import {assert} from 'chai';
|
||||
import Sequence, {SequenceCursor} from './sequence.js';
|
||||
import {notNull} from './assert.js';
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
// @flow
|
||||
|
||||
import {assert} from 'chai';
|
||||
import {suite, setup, teardown, test} from 'mocha';
|
||||
import {suite, setup, teardown, test} from './jest.js';
|
||||
|
||||
import Ref from './ref.js';
|
||||
import Set, {SetLeafSequence} from './set.js';
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
// @flow
|
||||
|
||||
import {assert} from 'chai';
|
||||
import {suite, test} from 'mocha';
|
||||
import {suite, test} from './jest.js';
|
||||
import {encodingLength, encode, decode, maxVarintLength} from './signed-varint.js';
|
||||
import {alloc} from './bytes.js';
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
// @flow
|
||||
|
||||
import {assert} from 'chai';
|
||||
import {suite, test} from 'mocha';
|
||||
import {suite, test} from './jest.js';
|
||||
import {invariant} from './assert.js';
|
||||
import {getHash} from './get-hash.js';
|
||||
import List from './list.js';
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
// @flow
|
||||
|
||||
import {assert} from 'chai';
|
||||
import {suite, test} from 'mocha';
|
||||
import {suite, test} from './jest.js';
|
||||
import {invariant} from './assert.js';
|
||||
import {getHash} from './get-hash.js';
|
||||
import List from './list.js';
|
||||
|
||||
@@ -22,7 +22,7 @@ import {
|
||||
numberType,
|
||||
stringType,
|
||||
} from './type.js';
|
||||
import {suite, test} from 'mocha';
|
||||
import {suite, test} from './jest.js';
|
||||
import {equals} from './compare.js';
|
||||
import List from './list.js';
|
||||
import Map from './map.js';
|
||||
|
||||
@@ -85,6 +85,16 @@ export default class Struct extends ValueBase {
|
||||
mirror.forEachField(add);
|
||||
return chunks;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the values of the struct in the same order as the fields. To get the field names you can
|
||||
* inspect the type or use a StructMirror.
|
||||
*/
|
||||
get values(): Value[] {
|
||||
// This is exposed this way to allow us breaking cyclic dependencies.
|
||||
// TODO: Use Symbol and expose symbol internally instead?
|
||||
return this._values;
|
||||
}
|
||||
}
|
||||
|
||||
function validate(type: Type<any>, values: Value[]): void {
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
// @flow
|
||||
|
||||
import {assert} from 'chai';
|
||||
import {suite, test} from 'mocha';
|
||||
import {suite, test} from './jest.js';
|
||||
import {Kind} from './noms-kind.js';
|
||||
import {equals} from './compare.js';
|
||||
import {
|
||||
|
||||
@@ -20,9 +20,10 @@ import {
|
||||
getTypeOfValue,
|
||||
} from './type.js';
|
||||
import type {Type} from './type.js';
|
||||
import {suite, test} from 'mocha';
|
||||
import {suite, test} from './jest.js';
|
||||
import {equals} from './compare.js';
|
||||
import {encodeValue, decodeValue} from './codec.js';
|
||||
import encodeValue from './encode-value.js';
|
||||
import decodeValue from './decode-value.js';
|
||||
import {notNull} from './assert.js';
|
||||
|
||||
suite('Type', () => {
|
||||
|
||||
@@ -24,7 +24,7 @@ import Set, {SetLeafSequence} from './set.js';
|
||||
import {MetaSequence} from './meta-sequence.js';
|
||||
import type Value from './value.js';
|
||||
import type {ValueReader} from './value-store.js';
|
||||
import type {NomsReader} from './codec.js';
|
||||
import type {NomsReader} from './noms-reader.js';
|
||||
import type TypeCache from './type-cache.js';
|
||||
|
||||
export default class ValueDecoder {
|
||||
|
||||
@@ -4,21 +4,22 @@
|
||||
|
||||
// @flow
|
||||
|
||||
import Blob, {BlobLeafSequence} from './blob.js';
|
||||
import List, {ListLeafSequence} from './list.js';
|
||||
import Map, {MapLeafSequence} from './map.js';
|
||||
import Ref, {constructRef} from './ref.js';
|
||||
import type {BlobLeafSequence} from './blob.js';
|
||||
import type {ListLeafSequence} from './list.js';
|
||||
import type {MapLeafSequence} from './map.js';
|
||||
import type Ref from './ref.js';
|
||||
import {constructRef} from './ref.js';
|
||||
import Sequence from './sequence.js';
|
||||
import Set, {SetLeafSequence} from './set.js';
|
||||
import Struct, {StructMirror} from './struct.js';
|
||||
import type {SetLeafSequence} from './set.js';
|
||||
import type Struct from './struct.js';
|
||||
import type Value from './value.js';
|
||||
import type {NomsKind} from './noms-kind.js';
|
||||
import type {NomsWriter} from './codec.js';
|
||||
import type {NomsWriter} from './noms-writer.js';
|
||||
import type {ValueWriter} from './value-store.js';
|
||||
import type {primitive} from './primitives.js';
|
||||
import {MetaTuple} from './meta-sequence.js';
|
||||
import {boolType, CycleDesc, getTypeOfValue, makeRefType, StructDesc, Type} from './type.js';
|
||||
import {describeTypeOfValue} from './encode-human-readable.js';
|
||||
import type {MetaTuple} from './meta-sequence.js';
|
||||
import {boolType, CycleDesc, getTypeOfValue, makeRefType, StructDesc} from './type.js';
|
||||
import type {Type} from './type.js';
|
||||
import {invariant, notNull} from './assert.js';
|
||||
import {isPrimitiveKind, kindToString, Kind} from './noms-kind.js';
|
||||
|
||||
@@ -111,7 +112,7 @@ export default class ValueEncoder {
|
||||
this._w.writeUint32(count);
|
||||
for (let i = 0; i < count; i++) {
|
||||
const tuple: MetaTuple<any> = v.items[i];
|
||||
invariant(tuple instanceof MetaTuple);
|
||||
// invariant(tuple instanceof MetaTuple);
|
||||
const child = tuple.child;
|
||||
if (child && this._vw) {
|
||||
this._vw.writeValue(child);
|
||||
@@ -135,85 +136,75 @@ export default class ValueEncoder {
|
||||
this._w.appendType(t);
|
||||
switch (t.kind) {
|
||||
case Kind.Blob: {
|
||||
invariant(v instanceof Blob,
|
||||
() => `Failed to write Blob. Invalid type: ${describeTypeOfValue(v)}`);
|
||||
// $FlowIssue: We know v is a Blob here.
|
||||
const sequence = v.sequence;
|
||||
if (this.maybeWriteMetaSequence(sequence)) {
|
||||
break;
|
||||
}
|
||||
|
||||
invariant(sequence instanceof BlobLeafSequence);
|
||||
this.writeBlobLeafSequence(sequence);
|
||||
break;
|
||||
}
|
||||
case Kind.Bool:
|
||||
invariant(typeof v === 'boolean',
|
||||
() => `Failed to write Bool. Invalid type: ${describeTypeOfValue(v)}`);
|
||||
this._w.writeBool(v);
|
||||
case Kind.Bool: {
|
||||
// $FlowIssue: We know b is a boolean here.
|
||||
const b: boolean = v;
|
||||
this._w.writeBool(b);
|
||||
break;
|
||||
case Kind.Number:
|
||||
invariant(typeof v === 'number',
|
||||
() => `Failed to write Number. Invalid type: ${describeTypeOfValue(v)}`);
|
||||
if (!Number.isFinite(v)) {
|
||||
throw new Error(`${v} is not a supported number`);
|
||||
}
|
||||
case Kind.Number: {
|
||||
// $FlowIssue: We know n is a number here.
|
||||
const n: number = v;
|
||||
if (!Number.isFinite(n)) {
|
||||
throw new Error(`${n} is not a supported number`);
|
||||
}
|
||||
this._w.writeNumber(v);
|
||||
this._w.writeNumber(n);
|
||||
break;
|
||||
}
|
||||
case Kind.List: {
|
||||
invariant(v instanceof List,
|
||||
() => `Failed to write List. Invalid type: ${describeTypeOfValue(v)}`);
|
||||
// $FlowIssue: We know v is a List here.
|
||||
const sequence = v.sequence;
|
||||
if (this.maybeWriteMetaSequence(sequence)) {
|
||||
break;
|
||||
}
|
||||
|
||||
invariant(sequence instanceof ListLeafSequence);
|
||||
this.writeListLeafSequence(sequence);
|
||||
break;
|
||||
}
|
||||
case Kind.Map: {
|
||||
invariant(v instanceof Map,
|
||||
() => `Failed to write Map. Invalid type: ${describeTypeOfValue(v)}`);
|
||||
// $FlowIssue: We know v is a Map here.
|
||||
const sequence = v.sequence;
|
||||
if (this.maybeWriteMetaSequence(sequence)) {
|
||||
break;
|
||||
}
|
||||
|
||||
invariant(sequence instanceof MapLeafSequence);
|
||||
this.writeMapLeafSequence(sequence);
|
||||
break;
|
||||
}
|
||||
case Kind.Ref:
|
||||
invariant(v instanceof Ref,
|
||||
() => `Failed to write Ref. Invalid type: ${describeTypeOfValue(v)}`);
|
||||
// $FlowIssue: We know v is a Ref here.
|
||||
this.writeRef(v);
|
||||
break;
|
||||
case Kind.Set: {
|
||||
invariant(v instanceof Set,
|
||||
() => `Failed to write Set. Invalid type: ${describeTypeOfValue(v)}`);
|
||||
// $FlowIssue: We know v is a Set here.
|
||||
const sequence = v.sequence;
|
||||
if (this.maybeWriteMetaSequence(sequence)) {
|
||||
break;
|
||||
}
|
||||
|
||||
invariant(sequence instanceof SetLeafSequence);
|
||||
this.writeSetLeafSequence(sequence);
|
||||
break;
|
||||
}
|
||||
case Kind.String:
|
||||
invariant(typeof v === 'string',
|
||||
() => `Failed to write String. Invalid type: ${describeTypeOfValue(v)}`);
|
||||
// $FlowIssue: We know v is a string here.
|
||||
this._w.writeString(v);
|
||||
break;
|
||||
|
||||
case Kind.Type:
|
||||
invariant(v instanceof Type,
|
||||
() => `Failed to write Type. Invalid type: ${describeTypeOfValue(v)}`);
|
||||
// $FlowIssue: We know v is a Type here.
|
||||
this.writeType(v, []);
|
||||
break;
|
||||
case Kind.Struct:
|
||||
invariant(v instanceof Struct,
|
||||
() => `Failed to write Struct. Invalid type: ${describeTypeOfValue(v)}`);
|
||||
// $FlowIssue: We know v is a Struct here.
|
||||
this.writeStruct(v);
|
||||
break;
|
||||
case Kind.Cycle:
|
||||
@@ -226,10 +217,10 @@ export default class ValueEncoder {
|
||||
}
|
||||
|
||||
writeStruct(s: Struct) {
|
||||
const mirror = new StructMirror(s);
|
||||
mirror.forEachField(field => {
|
||||
this.writeValue(field.value);
|
||||
});
|
||||
const {values} = s;
|
||||
for (let i = 0; i < values.length; i++) {
|
||||
this.writeValue(values[i]);
|
||||
}
|
||||
}
|
||||
|
||||
writeCycle(i: number) {
|
||||
|
||||
@@ -4,13 +4,13 @@
|
||||
|
||||
// @flow
|
||||
|
||||
import {suite, test} from 'mocha';
|
||||
import {suite, test} from './jest.js';
|
||||
import {assert} from 'chai';
|
||||
import MemoryStore from './memory-store.js';
|
||||
import {BatchStoreAdaptor} from './batch-store.js';
|
||||
import ValueStore from './value-store.js';
|
||||
import List from './list.js';
|
||||
import {encodeValue} from './codec.js';
|
||||
import encodeValue from './encode-value.js';
|
||||
import {equals} from './compare.js';
|
||||
import Hash from './hash.js';
|
||||
import {getHash} from './get-hash.js';
|
||||
|
||||
@@ -18,9 +18,9 @@ import {
|
||||
} from './type.js';
|
||||
import {Kind} from './noms-kind.js';
|
||||
import {ValueBase} from './value.js';
|
||||
import {decodeValue} from './codec.js';
|
||||
import decodeValue from './decode-value.js';
|
||||
import {invariant, notNull} from './assert.js';
|
||||
import {encodeValue} from './codec.js';
|
||||
import encodeValue from './encode-value.js';
|
||||
import {describeType, describeTypeOfValue} from './encode-human-readable.js';
|
||||
import {equals} from './compare.js';
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
// @flow
|
||||
|
||||
import {suite, suiteSetup, suiteTeardown, test} from 'mocha';
|
||||
import {suite, suiteSetup, suiteTeardown, test} from './jest.js';
|
||||
import {assert} from 'chai';
|
||||
|
||||
import {createStructClass} from './struct.js';
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
// @flow
|
||||
|
||||
import {assert} from 'chai';
|
||||
import {suite, test} from 'mocha';
|
||||
import {suite, test} from './jest.js';
|
||||
import type Value from './value.js';
|
||||
import {TestDatabase} from './test-util.js';
|
||||
import {equals} from './compare.js';
|
||||
|
||||
+601
-17
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user