Skip to content

Commit

Permalink
build: run tests in band (#272)
Browse files Browse the repository at this point in the history
* build: attempt to fix migration

* fix: test again

* fix: log migrations

* fix: try removing migrations

* test: migrations on the outside

* fix: return migs

* test: delete some migrations

* test: return some migs

* test: remove more

* test: more

* fix: try without logs and without mv data

* test: revert migrations

* fix: run tests in band
  • Loading branch information
rafaelcr authored Nov 17, 2023
1 parent 13e1f16 commit 5b1db36
Show file tree
Hide file tree
Showing 9 changed files with 73 additions and 24 deletions.
56 changes: 49 additions & 7 deletions package-lock.json

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

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"build": "rimraf ./dist && tsc --project tsconfig.build.json",
"start": "node dist/src/index.js",
"start-ts": "ts-node ./src/index.ts",
"test": "jest",
"test": "jest --runInBand",
"migrate": "ts-node node_modules/.bin/node-pg-migrate -j ts",
"lint:eslint": "eslint . --ext .js,.jsx,.ts,.tsx -f unix",
"lint:prettier": "prettier --check src/**/*.ts tests/**/*.ts migrations/**/*.ts",
Expand Down Expand Up @@ -50,7 +50,7 @@
"@fastify/multipart": "^7.1.0",
"@fastify/swagger": "^8.3.1",
"@fastify/type-provider-typebox": "^3.2.0",
"@hirosystems/api-toolkit": "^1.3.0",
"@hirosystems/api-toolkit": "^1.3.1",
"@hirosystems/chainhook-client": "^1.4.1",
"@semantic-release/changelog": "^6.0.3",
"@semantic-release/commit-analyzer": "^10.0.4",
Expand Down
5 changes: 3 additions & 2 deletions tests/brc20.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { cycleMigrations } from '@hirosystems/api-toolkit';
import { runMigrations } from '@hirosystems/api-toolkit';
import { buildApiServer } from '../src/api/init';
import { Brc20ActivityResponse, Brc20TokenResponse } from '../src/api/schemas';
import { brc20FromInscription } from '../src/pg/brc20/helpers';
Expand Down Expand Up @@ -72,14 +72,15 @@ describe('BRC-20', () => {
};

beforeEach(async () => {
await runMigrations(MIGRATIONS_DIR, 'up');
db = await PgStore.connect({ skipMigrations: true });
fastify = await buildApiServer({ db });
await cycleMigrations(MIGRATIONS_DIR);
});

afterEach(async () => {
await fastify.close();
await db.close();
await runMigrations(MIGRATIONS_DIR, 'down');
});

describe('token standard validation', () => {
Expand Down
5 changes: 3 additions & 2 deletions tests/cache.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { cycleMigrations } from '@hirosystems/api-toolkit';
import { runMigrations } from '@hirosystems/api-toolkit';
import { buildApiServer } from '../src/api/init';
import { MIGRATIONS_DIR, PgStore } from '../src/pg/pg-store';
import { TestChainhookPayloadBuilder, TestFastifyServer, randomHash } from './helpers';
Expand All @@ -8,14 +8,15 @@ describe('ETag cache', () => {
let fastify: TestFastifyServer;

beforeEach(async () => {
await runMigrations(MIGRATIONS_DIR, 'up');
db = await PgStore.connect({ skipMigrations: true });
fastify = await buildApiServer({ db });
await cycleMigrations(MIGRATIONS_DIR);
});

afterEach(async () => {
await fastify.close();
await db.close();
await runMigrations(MIGRATIONS_DIR, 'down');
});

test('inscription cache control', async () => {
Expand Down
5 changes: 3 additions & 2 deletions tests/inscriptions.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { cycleMigrations } from '@hirosystems/api-toolkit';
import { runMigrations } from '@hirosystems/api-toolkit';
import { buildApiServer } from '../src/api/init';
import { MIGRATIONS_DIR, PgStore } from '../src/pg/pg-store';
import { TestChainhookPayloadBuilder, TestFastifyServer, rollBack } from './helpers';
Expand All @@ -12,14 +12,15 @@ describe('/inscriptions', () => {
let fastify: TestFastifyServer;

beforeEach(async () => {
await runMigrations(MIGRATIONS_DIR, 'up');
db = await PgStore.connect({ skipMigrations: true });
fastify = await buildApiServer({ db });
await cycleMigrations(MIGRATIONS_DIR);
});

afterEach(async () => {
await fastify.close();
await db.close();
await runMigrations(MIGRATIONS_DIR, 'down');
});

describe('show', () => {
Expand Down
5 changes: 3 additions & 2 deletions tests/sats.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { cycleMigrations } from '@hirosystems/api-toolkit';
import { runMigrations } from '@hirosystems/api-toolkit';
import { buildApiServer } from '../src/api/init';
import { MIGRATIONS_DIR, PgStore } from '../src/pg/pg-store';
import { TestChainhookPayloadBuilder, TestFastifyServer } from './helpers';
Expand All @@ -8,14 +8,15 @@ describe('/sats', () => {
let fastify: TestFastifyServer;

beforeEach(async () => {
await runMigrations(MIGRATIONS_DIR, 'up');
db = await PgStore.connect({ skipMigrations: true });
fastify = await buildApiServer({ db });
await cycleMigrations(MIGRATIONS_DIR);
});

afterEach(async () => {
await fastify.close();
await db.close();
await runMigrations(MIGRATIONS_DIR, 'down');
});

test('returns valid sat', async () => {
Expand Down
7 changes: 4 additions & 3 deletions tests/server.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@ import {
ChainhookEventObserver,
} from '@hirosystems/chainhook-client';
import { buildApiServer } from '../src/api/init';
import { cycleMigrations } from '@hirosystems/api-toolkit';
import { runMigrations } from '@hirosystems/api-toolkit';

describe('EventServer', () => {
let db: PgStore;
let server: ChainhookEventObserver;
let fastify: TestFastifyServer;

beforeEach(async () => {
db = await PgStore.connect({ skipMigrations: true });
await cycleMigrations(MIGRATIONS_DIR);
await runMigrations(MIGRATIONS_DIR, 'up');
ENV.CHAINHOOK_AUTO_PREDICATE_REGISTRATION = false;
db = await PgStore.connect({ skipMigrations: true });
server = await startChainhookServer({ db });
fastify = await buildApiServer({ db });
});
Expand All @@ -28,6 +28,7 @@ describe('EventServer', () => {
await server.close();
await fastify.close();
await db.close();
await runMigrations(MIGRATIONS_DIR, 'down');
});

describe('parser', () => {
Expand Down
5 changes: 3 additions & 2 deletions tests/stats.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { cycleMigrations } from '@hirosystems/api-toolkit';
import { runMigrations } from '@hirosystems/api-toolkit';
import { buildApiServer } from '../src/api/init';
import { MIGRATIONS_DIR, PgStore } from '../src/pg/pg-store';
import { TestChainhookPayloadBuilder, TestFastifyServer, randomHash } from './helpers';
Expand All @@ -8,14 +8,15 @@ describe('/stats', () => {
let fastify: TestFastifyServer;

beforeEach(async () => {
await runMigrations(MIGRATIONS_DIR, 'up');
db = await PgStore.connect({ skipMigrations: true });
fastify = await buildApiServer({ db });
await cycleMigrations(MIGRATIONS_DIR);
});

afterEach(async () => {
await fastify.close();
await db.close();
await runMigrations(MIGRATIONS_DIR, 'down');
});

describe('/stats/inscriptions', () => {
Expand Down
5 changes: 3 additions & 2 deletions tests/status.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { cycleMigrations } from '@hirosystems/api-toolkit';
import { runMigrations } from '@hirosystems/api-toolkit';
import { buildApiServer } from '../src/api/init';
import { MIGRATIONS_DIR, PgStore } from '../src/pg/pg-store';
import { TestChainhookPayloadBuilder, TestFastifyServer } from './helpers';
Expand All @@ -8,14 +8,15 @@ describe('Status', () => {
let fastify: TestFastifyServer;

beforeEach(async () => {
await runMigrations(MIGRATIONS_DIR, 'up');
db = await PgStore.connect({ skipMigrations: true });
fastify = await buildApiServer({ db });
await cycleMigrations(MIGRATIONS_DIR);
});

afterEach(async () => {
await fastify.close();
await db.close();
await runMigrations(MIGRATIONS_DIR, 'down');
});

test('returns status when db is empty', async () => {
Expand Down

0 comments on commit 5b1db36

Please sign in to comment.