Skip to content

Commit

Permalink
Migrate tests to latest rules-nodejs (typedb#48)
Browse files Browse the repository at this point in the history
## What is the goal of this PR?

Our fork of `rules-nodejs` is ~600 commits behind the official upstream repo and it's time to switch to upstream rules so it's easier to keep up.

## What are the changes implemented in this PR?

* Migrate `nodejs_jest_test` to `jasmine_node_test`
  * `it()` instead of `test()` in test definitions
  * `expect(obj).toHaveLength(len)` is not available in Jasmine, so we use `expect(obj.length).toBe(len)`. This corresponds to exact [definition](https://jestjs.io/docs/en/expect.html#tohavelengthnumber) of what original function does.
  * `xit()` instead of `test.skip()`
  * `jasmine.DEFAULT_TIMEOUT_INTERVAL` instead of `jest.setTimeout`
  * `await expectAsync(promise).toBeRejected();` instead of `await expect(promise).rejects.toThrowError();` 
* Use `yarn` to install dependencies instead of `npm`:
  * this is a currently-recommended way by `rules-nodejs` (see their `README`)
  * `grpc` failed to install with `npm_install` — planning to open an issue soon
* Add `node_modules` to `.gitignore` — `rules-nodejs` now install Node deps right into workspace
  • Loading branch information
vmax authored Jul 19, 2019
1 parent ca00e36 commit bccbbd5
Show file tree
Hide file tree
Showing 20 changed files with 1,425 additions and 137 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
bazel-*
.ijwb
node_modules
65 changes: 29 additions & 36 deletions BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -18,42 +18,35 @@

exports_files([
"package.json",
"yarn.lock",
"VERSION",
"deployment.properties",
"RELEASE_TEMPLATE.md",
])

load("@build_bazel_rules_nodejs//:defs.bzl", "npm_package", "nodejs_jest_test", "babel_library")
load("@build_bazel_rules_nodejs//:defs.bzl", "npm_package")
load("@npm_bazel_jasmine//:index.bzl", "jasmine_node_test")
load("@graknlabs_bazel_distribution//npm:rules.bzl", "assemble_npm", "deploy_npm")
load("@graknlabs_bazel_distribution//github:rules.bzl", "deploy_github")


babel_library(
name = 'bundle',
npm_package(
name = "client-nodejs",
srcs = glob([
"package.json",
"src/*.js",
"src/service/Keyspace/KeyspaceService.js",
"src/service/Session/*.js",
"src/service/Session/util/*.js",
"src/service/Session/concept/*.js",
]),
data = [
"package.json",
"README.md",
".npmignore"
],
babel = "@nodejs_dependencies//@bazel/babel/bin:babel",
babelrc = "babel.rc.js"
)


npm_package(
name = "client-nodejs",
]),
deps = [
"@graknlabs_protocol//grpc/nodejs:protocol",
":bundle",
"@nodejs_dependencies//grpc",
"@nodejs_dependencies//google-protobuf"
"@npm//grpc",
"@npm//google-protobuf"
],
visibility = ["//visibility:public"],
vendor_external = [
Expand Down Expand Up @@ -83,20 +76,19 @@ deploy_github(

NODEJS_TEST_DEPENDENCIES = [
":client-nodejs",
"@nodejs_dependencies//fs-extra",
"@nodejs_dependencies//google-protobuf",
"@nodejs_dependencies//grpc",
"@nodejs_dependencies//jest",
"@nodejs_dependencies//tmp",
"@nodejs_dependencies//unzipper"
"@npm//fs-extra",
"@npm//google-protobuf",
"@npm//grpc",
"@npm//tmp",
"@npm//unzipper"
]

NODEJS_TEST_DATA = [
"@graknlabs_grakn_core//:assemble-mac-zip",
"tests/support/basic-genealogy.gql"
]

nodejs_jest_test(
jasmine_node_test(
name = "keyspace-test",
srcs = [
"tests/support/GraknTestEnvironment.js",
Expand All @@ -106,7 +98,8 @@ nodejs_jest_test(
data = NODEJS_TEST_DATA,
)

nodejs_jest_test(

jasmine_node_test(
name = "concept-test",
srcs = [
"tests/support/GraknTestEnvironment.js",
Expand All @@ -116,7 +109,7 @@ nodejs_jest_test(
data = NODEJS_TEST_DATA,
)

nodejs_jest_test(
jasmine_node_test(
name = "schemaconcept-test",
srcs = [
"tests/support/GraknTestEnvironment.js",
Expand All @@ -126,7 +119,7 @@ nodejs_jest_test(
data = NODEJS_TEST_DATA,
)

nodejs_jest_test(
jasmine_node_test(
name = "rule-test",
srcs = [
"tests/support/GraknTestEnvironment.js",
Expand All @@ -136,7 +129,7 @@ nodejs_jest_test(
data = NODEJS_TEST_DATA,
)

nodejs_jest_test(
jasmine_node_test(
name = "type-test",
srcs = [
"tests/support/GraknTestEnvironment.js",
Expand All @@ -146,7 +139,7 @@ nodejs_jest_test(
data = NODEJS_TEST_DATA,
)

nodejs_jest_test(
jasmine_node_test(
name = "attribute-test",
srcs = [
"tests/support/GraknTestEnvironment.js",
Expand All @@ -156,7 +149,7 @@ nodejs_jest_test(
data = NODEJS_TEST_DATA,
)

nodejs_jest_test(
jasmine_node_test(
name = "attributetype-test",
srcs = [
"tests/support/GraknTestEnvironment.js",
Expand All @@ -166,7 +159,7 @@ nodejs_jest_test(
data = NODEJS_TEST_DATA,
)

nodejs_jest_test(
jasmine_node_test(
name = "role-test",
srcs = [
"tests/support/GraknTestEnvironment.js",
Expand All @@ -176,7 +169,7 @@ nodejs_jest_test(
data = NODEJS_TEST_DATA,
)

nodejs_jest_test(
jasmine_node_test(
name = "grakntx-test",
srcs = [
"tests/support/GraknTestEnvironment.js",
Expand All @@ -186,7 +179,7 @@ nodejs_jest_test(
data = NODEJS_TEST_DATA
)

nodejs_jest_test(
jasmine_node_test(
name = "relation-test",
srcs = [
"tests/support/GraknTestEnvironment.js",
Expand All @@ -196,7 +189,7 @@ nodejs_jest_test(
data = NODEJS_TEST_DATA,
)

nodejs_jest_test(
jasmine_node_test(
name = "relationtype-test",
srcs = [
"tests/support/GraknTestEnvironment.js",
Expand All @@ -206,7 +199,7 @@ nodejs_jest_test(
data = NODEJS_TEST_DATA,
)

nodejs_jest_test(
jasmine_node_test(
name = "thing-test",
srcs = [
"tests/support/GraknTestEnvironment.js",
Expand All @@ -216,7 +209,7 @@ nodejs_jest_test(
data = NODEJS_TEST_DATA,
)

nodejs_jest_test(
jasmine_node_test(
name = "entitytype-test",
srcs = [
"tests/support/GraknTestEnvironment.js",
Expand All @@ -226,7 +219,7 @@ nodejs_jest_test(
data = NODEJS_TEST_DATA,
)

nodejs_jest_test(
jasmine_node_test(
name = "committx-test",
srcs = [
"tests/support/GraknTestEnvironment.js",
Expand Down
17 changes: 6 additions & 11 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -62,21 +62,16 @@ graknlabs_build_tools_ci_pip_install()
load("@graknlabs_build_tools//bazel:dependencies.bzl", "bazel_rules_nodejs")
bazel_rules_nodejs()

load("@build_bazel_rules_nodejs//:package.bzl", "rules_nodejs_dependencies")
rules_nodejs_dependencies()

load("@build_bazel_rules_nodejs//:defs.bzl", "node_repositories", "npm_install")
load("@build_bazel_rules_nodejs//:defs.bzl", "node_repositories", "yarn_install")
node_repositories(package_json = ["//:package.json"])
npm_install(
name = "nodejs_dependencies",
yarn_install(
name = "npm",
package_json = "//:package.json",
data = [
"@build_bazel_rules_nodejs//internal/babel_library:package.json",
"@build_bazel_rules_nodejs//internal/babel_library:babel.js",
"@build_bazel_rules_nodejs//internal/babel_library:yarn.lock",
],
yarn_lock = "//:yarn.lock"
)

load("@npm//:install_bazel_dependencies.bzl", "install_bazel_dependencies")
install_bazel_dependencies()

##########################
# Load GRPC dependencies #
Expand Down
7 changes: 3 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,13 @@
},
"dependencies": {
"google-protobuf": "^3.6.0",
"grpc": "^1.12.3"
"grpc": "^1.22.2"
},
"devDependencies": {
"@bazel/babel": "file:internal/babel_library",
"fs-extra": "^7.0.0",
"grpc-tools": "^1.6.6",
"jest": "^23.4.0",
"tmp": "0.1.0",
"unzipper": "0.9.11"
"unzipper": "0.9.11",
"@bazel/jasmine": "latest"
}
}
2 changes: 1 addition & 1 deletion tests/service/keyspace/Keyspace.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ afterAll(async () => {

describe("Keyspace methods", () => {

test("retrieve and delete", async () => {
it("retrieve and delete", async () => {
const session = await graknClient.session("retrievetest");
const tx = await session.transaction().write();
tx.close();
Expand Down
8 changes: 4 additions & 4 deletions tests/service/session/transaction/Attribute.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ afterEach(() => {

describe("Attribute methods", () => {

test("value", async () => {
it("value", async () => {
const doubleAttributeType = await tx.putAttributeType("length", env.dataType().DOUBLE);
const doubleAttribute = await doubleAttributeType.create(11.58);
expect(await doubleAttribute.value()).toBe(11.58);
});

test("get value Date", async () => {
it("get value Date", async () => {
const dateType = await tx.putAttributeType("birth-date", env.dataType().DATE);
const personType = await tx.putEntityType('person');
await personType.has(dateType);
Expand All @@ -59,7 +59,7 @@ describe("Attribute methods", () => {
expect(value instanceof Date).toBeTruthy();
});

test("set value Date", async () => {
it("set value Date", async () => {
const dateType = await tx.putAttributeType("birth-date", env.dataType().DATE);
const testDate = new Date('2018-08-06');
const date = await dateType.create(testDate);
Expand All @@ -68,7 +68,7 @@ describe("Attribute methods", () => {
expect(testDate.getTime()).toEqual(value.getTime());
});

test("owners", async () => {
it("owners", async () => {
const personType = await tx.putEntityType('person');
const animalType = await tx.putEntityType('animal');
const nameType = await tx.putAttributeType("name", env.dataType().STRING);
Expand Down
10 changes: 5 additions & 5 deletions tests/service/session/transaction/AttributeType.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ afterEach(() => {

describe("Attribute type methods", () => {

test("create", async () => {
it("create", async () => {
const attributeType = await tx.putAttributeType("firstname", env.dataType().STRING);
const attribute = await attributeType.create('Marco');
expect(attribute.isAttribute()).toBeTruthy();
Expand All @@ -55,7 +55,7 @@ describe("Attribute type methods", () => {
expect(await doubleAttribute.value()).toBe(11.58);
});

test('dataType', async () => {
it('dataType', async () => {
const attributeType = await tx.putAttributeType("firstname", env.dataType().STRING);
expect(await attributeType.dataType()).toBe('String');

Expand All @@ -66,7 +66,7 @@ describe("Attribute type methods", () => {
expect(await doubleAttributeType.dataType()).toBe('Double');
});

test('attribute', async () => {
it('attribute', async () => {
const attributeType = await tx.putAttributeType("firstname", env.dataType().STRING);
await attributeType.create('Marco');
const attribute = await attributeType.attribute('Marco');
Expand All @@ -75,10 +75,10 @@ describe("Attribute type methods", () => {
expect(nullAttribute).toBeNull();
});

test('set/get regex', async () => {
it('set/get regex', async () => {
const attributeType = await tx.putAttributeType("id", env.dataType().STRING);
const emptyRegex = await attributeType.regex();
expect(emptyRegex).toHaveLength(0);
expect(emptyRegex.length).toBe(0);

await attributeType.regex("(good|bad)-dog");
const regex = await attributeType.regex();
Expand Down
20 changes: 10 additions & 10 deletions tests/service/session/transaction/CommitTx.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,28 +30,28 @@ beforeAll(async () => {

afterAll(async () => {
await session.close();
graknClient.keyspaces().delete("testcommit");
env.tearDown();
await graknClient.keyspaces().delete("testcommit");
await env.tearDown();
});

describe('Integration test', () => {

test("Tx open in READ mode should throw when trying to define", async () => {
it("Tx open in READ mode should throw when trying to define", async () => {
const tx = await session.transaction().read();
await expect(tx.query("define person sub entity;")).rejects.toThrowError();
await expectAsync(tx.query("define person sub entity;")).toBeRejected();
tx.close();
});

test("If tx does not commit, different Tx won't see changes", async () => {
it("If tx does not commit, different Tx won't see changes", async () => {
const tx = await session.transaction().write();
await tx.query("define catwoman sub entity;");
tx.close()
const newTx = await session.transaction().write();
await expect(newTx.query("match $x sub catwoman; get;")).rejects.toThrowError(); // catwoman label does not exist in the graph
await expectAsync(newTx.query("match $x sub catwoman; get;")).toBeRejected(); // catwoman label does not exist in the graph
newTx.close();
});

test("When tx commit, different tx will see changes", async () => {
it("When tx commit, different tx will see changes", async () => {
const tx = await session.transaction().write();
await tx.query("define superman sub entity;");
await tx.commit();
Expand All @@ -61,7 +61,7 @@ describe('Integration test', () => {
newTx.close();
});

test.skip("explanation and default of infer is true", async () => {
xit("explanation and default of infer is true", async () => {
const localSession = await graknClient.session("gene");
const tx = await localSession.transaction().write();
const iterator = await tx.query("match $x isa cousins; get;"); // TODO: put back offset 0; limit 1;
Expand All @@ -73,7 +73,7 @@ describe('Integration test', () => {
await localSession.close();
});

test.skip("explanation with join explanation", async () => {
xit("explanation with join explanation", async () => {
const localSession = await graknClient.session("gene");
const tx = await localSession.transaction().write();
const iterator = await tx.query(`match ($x, $y) isa marriage; ($y, $z) isa marriage;
Expand All @@ -87,7 +87,7 @@ describe('Integration test', () => {
await localSession.close();
});

test.skip("no results with infer false", async () => {
xit("no results with infer false", async () => {
const localSession = await graknClient.session("gene");
const tx = await localSession.transaction().write();
const iterator = await tx.query("match $x isa cousins; get;", { infer: false }); // TODO: put back offset 0; limit 1;
Expand Down
Loading

0 comments on commit bccbbd5

Please sign in to comment.