Skip to content
This repository has been archived by the owner on Mar 23, 2021. It is now read-only.

Commit

Permalink
Add TS Linter and allow e2e tests to be run with yarn
Browse files Browse the repository at this point in the history
The dev env for e2e tests is actually not great. Being able to run
the test with yarn allows more flexibility.

Linter and prettier allows better standard for the TypeScript code too.
  • Loading branch information
Franck Royer committed Jul 17, 2019
1 parent 6c9912e commit 2fe91ea
Show file tree
Hide file tree
Showing 36 changed files with 667 additions and 475 deletions.
2 changes: 1 addition & 1 deletion .githooks/pre-commit
Expand Up @@ -14,7 +14,7 @@ function check_rs() {

function check_ts() {
if (( dry == 0 )); then
cargo make check-ts-format
cargo make check-ts
else
echo "check_ts ran"
fi
Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

64 changes: 15 additions & 49 deletions Makefile.toml
Expand Up @@ -11,7 +11,7 @@ workspace = false
clear = true
dependencies = [
"format",
"ts-format",
"fix-ts",
"build",
"test"
]
Expand All @@ -21,7 +21,6 @@ dependencies = [
workspace = false
dependencies = [
"check-rs-format",
"check-ts-format",
"check-ts",
"check-cargo-toml-format",
"clippy"
Expand Down Expand Up @@ -126,28 +125,14 @@ script = [
"cargo +nightly-2019-04-30 fmt -- --check"
]

[tasks.ts-format]
description = "Runs prettier to format TypeScript code."
[tasks.fix-ts]
description = "Runs prettier & tslint to format TypeScript code."
workspace = false
install_script = ["(cd ./api_tests; yarn install;)"]
script = [
'''
(cd api_tests; yarn run prettier --write '**/*.{ts,json,yml}')
'''
]

[tasks.check-ts-format]
description = "Runs prettier to check appropriate TypeScript code format."
workspace = false
install_script = ["(cd ./api_tests; yarn install;)"]
script = [
'''
(cd api_tests; yarn run prettier --check '**/*.{ts,json,yml}')
'''
]
script = ["cd api_tests; yarn run fix"]

[tasks.check-ts]
description = "Runs tsc to validate TypeScript syntax."
description = "Runs tsc, prettier & tslint to validate TypeScript syntax & format."
workspace = false
install_script = ["(cd ./api_tests; yarn install;)"]
script = ["cd api_tests; yarn run check"]
Expand Down Expand Up @@ -199,12 +184,7 @@ dependencies = [
description = "Runs tests that don't require any external services"
workspace = false
private = true
script = [
'''
./api_tests/node_modules/.bin/ts-node --project ./api_tests/tsconfig.json \
./api_tests/harness.ts ./api_tests/dry/*.ts
'''
]
script = ['cd api_tests; yarn run test ./dry/*']

#########################
# Web GUI api Test flow #
Expand All @@ -222,11 +202,7 @@ description = "Runs tests to ensure that comit_node serves comit-i"
workspace = false
private = true
script = [
'''
./api_tests/node_modules/.bin/ts-node --project ./api_tests/tsconfig.json \
./api_tests/harness.ts ./api_tests/webgui/*.ts
'''
]
"cd ./api_tests; yarn run test ./webgui/*"]

#################
# E2E Test flow #
Expand All @@ -246,19 +222,20 @@ dependencies = [
description = "Runs RFC003 end-to-end tests specified on command line. Supports GLOB."
workspace = false
private = true
install_script = ["(cd ./api_tests; yarn install;)"]
script_runner = "bash"
script = [
'''
cd ./api_tests;
glob="${1:-*}";
for dir in api_tests/e2e/rfc003/$glob; do
for dir in e2e/rfc003/$glob; do
add_test_files=$(ls "$dir/"*.ts 2>/dev/null|| true);
if test "$add_test_files"; then
files="$files $add_test_files"
fi
done;
./api_tests/node_modules/.bin/ts-node --project ./api_tests/tsconfig.json \
./api_tests/harness.ts $files;
yarn run test $files;
'''
]

Expand All @@ -277,13 +254,8 @@ dependencies = [
description = "Runs btsieve API tests."
workspace = false
private = true
script_runner = "bash"
script = [
'''
./api_tests/node_modules/.bin/ts-node --project ./api_tests/tsconfig.json \
./api_tests/harness.ts ./api_tests/btsieve/*/*.ts
'''
]
install_script = ["(cd ./api_tests; yarn install;)"]
script = ["cd ./api_tests; yarn run test btsieve"]

######################################
# all API Tests flow #
Expand All @@ -300,11 +272,5 @@ dependencies = [
description = "Runs all API tests."
workspace = false
private = true
script_runner = "bash"
script = [
'''
./api_tests/node_modules/.bin/ts-node --project ./api_tests/tsconfig.json \
./api_tests/harness.ts \
./api_tests/{dry,webgui,btsieve/*,e2e/*/*}/*.ts
'''
]
install_script = ["(cd ./api_tests; yarn install;)"]
script = ["cd ./api_tests; yarn run test"]
42 changes: 21 additions & 21 deletions api_tests/btsieve/bitcoin_only/test.ts
@@ -1,9 +1,9 @@
import * as bitcoin from "../../lib/bitcoin";
import { Wallet } from "../../lib/wallet";
import { expect, request } from "chai";
import { HarnessGlobal } from "../../lib/util";
import * as bitcoin from "../../lib/bitcoin";
import { Btsieve, IdMatch } from "../../lib/btsieve";
import "../../lib/setupChai";
import { HarnessGlobal } from "../../lib/util";
import { Wallet } from "../../lib/wallet";

declare var global: HarnessGlobal;

Expand All @@ -25,7 +25,7 @@ setTimeout(async function() {
describe("Bitcoin", () => {
describe("Transactions", () => {
it("btsieve should respond not found when getting a non-existent bitcoin transaction query", async function() {
let res = await request(btsieve.url()).get(
const res = await request(btsieve.url()).get(
"/queries/bitcoin/regtest/transactions/1"
);

Expand All @@ -37,20 +37,20 @@ setTimeout(async function() {
let location: string;

it("btsieve should respond not found when creating a bitcoin transaction query for an invalid network", async function() {
let res = await request(btsieve.url())
const res = await request(btsieve.url())
.post("/queries/bitcoin/banananet/transactions")
.send({
to_address: to_address,
to_address,
});

expect(res).to.have.status(404);
});

it("btsieve should respond with location when creating a valid bitcoin transaction query", async function() {
let res = await request(btsieve.url())
const res = await request(btsieve.url())
.post("/queries/bitcoin/regtest/transactions")
.send({
to_address: to_address,
to_address,
});

location = res.header.location;
Expand All @@ -60,7 +60,7 @@ setTimeout(async function() {
});

it("btsieve should respond with no match when querying an existing bitcoin transaction query", async function() {
let res = await request(
const res = await request(
btsieve.absoluteLocation(location)
).get("");

Expand All @@ -75,7 +75,7 @@ setTimeout(async function() {

await bitcoin.generate(1);

let body = await btsieve.pollUntilMatches<IdMatch>(
const body = await btsieve.pollUntilMatches<IdMatch>(
btsieve.absoluteLocation(location)
);

Expand All @@ -89,7 +89,7 @@ setTimeout(async function() {
it("btsieve should respond with full transaction details when requesting on the `to_address` bitcoin transaction query with `return_as=transaction`", async function() {
await bitcoin.generate(1);

let res = await request(
const res = await request(
btsieve.absoluteLocation(location)
).get("?return_as=transaction");

Expand All @@ -104,7 +104,7 @@ setTimeout(async function() {
});

it("btsieve should respond with no content when deleting an existing bitcoin transaction query", async function() {
let res = await request(
const res = await request(
btsieve.absoluteLocation(location)
).del("");

Expand All @@ -114,7 +114,7 @@ setTimeout(async function() {

describe("Blocks", () => {
it("btsieve should respond not found when getting a non-existent bitcoin block query", async function() {
let res = await request(btsieve.url()).get(
const res = await request(btsieve.url()).get(
"/queries/bitcoin/regtest/blocks/1"
);

Expand All @@ -124,20 +124,20 @@ setTimeout(async function() {
const min_height = 200;
let location: string;
it("btsieve should respond not found when creating a bitcoin block query for an invalid network", async function() {
let res = await request(btsieve.url())
const res = await request(btsieve.url())
.post("/queries/bitcoin/banananet/blocks")
.send({
min_height: min_height,
min_height,
});

expect(res).to.have.status(404);
});

it("btsieve should respond with location when creating a valid bitcoin block query", async function() {
let res = await request(btsieve.url())
const res = await request(btsieve.url())
.post("/queries/bitcoin/regtest/blocks")
.send({
min_height: min_height,
min_height,
});

location = res.header.location;
Expand All @@ -147,7 +147,7 @@ setTimeout(async function() {
});

it("btsieve should respond with no match when querying an existing bitcoin block query", async function() {
let res = await request(
const res = await request(
btsieve.absoluteLocation(location)
).get("");

Expand All @@ -160,7 +160,7 @@ setTimeout(async function() {
this.slow(500);
await bitcoin.generate(50);

let res = await request(
const res = await request(
btsieve.absoluteLocation(location)
).get("");

Expand All @@ -174,7 +174,7 @@ setTimeout(async function() {
this.timeout(3000);

await bitcoin.generate(50);
let body = await btsieve.pollUntilMatches<IdMatch>(
const body = await btsieve.pollUntilMatches<IdMatch>(
btsieve.absoluteLocation(location)
);

Expand All @@ -183,7 +183,7 @@ setTimeout(async function() {
});

it("btsieve should respond with no content when deleting an existing bitcoin block query", async function() {
let res = await request(
const res = await request(
btsieve.absoluteLocation(location)
).del("");

Expand Down

0 comments on commit 2fe91ea

Please sign in to comment.