Skip to content

Commit

Permalink
Run itest with mocha
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremyjams committed Oct 29, 2024
1 parent e290803 commit 852f818
Show file tree
Hide file tree
Showing 12 changed files with 528 additions and 247 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,4 @@ jobs:
run: npm run test
- name: Test build
run: npm run build
# - name: Run integration tests
# run: npm run itest:all
# See Jenkinsfile-itest for "Run integration tests" step
6 changes: 6 additions & 0 deletions .mocharc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"extension": ["ts"],
"spec": "itest/**/*.ts",
"require": ["ts-node/register"],
"timeout": 300000
}
25 changes: 10 additions & 15 deletions Jenkinsfile-itest
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,25 @@ node('docker') {
checkoutInfo = checkout(scm)
echo "git checkout: ${checkoutInfo}"
}
stage('Pull') {
stage('Pull images') {
withCredentials([
usernamePassword(credentialsId: 'docker-regis',
usernameVariable: 'username', passwordVariable: 'password')
]) {
def registry = 'docker-regis.iex.ec'
sh "echo -n '${password}' | docker login --username '${username}' --password-stdin ${registry}"
sh 'cd docker/test/ && docker compose pull chain'
//sh './docker/test/up.sh'
sh "docker logout ${registry}"
}
}
docker.image('node:22-alpine').inside('-v /var/run/docker.sock:/var/run/docker.sock --network=host --user=root') {
stage('Init') {
sh 'apk add docker docker-compose'
sh 'npm ci'
docker.image('node:22-alpine')
.inside('-v /var/run/docker.sock:/var/run/docker.sock --network=host --user=root') {
stage('Init') {
sh 'apk add docker docker-compose' // TODO: Use already built image for a faster job
sh 'npm ci'
}
stage('Integration tests') {
sh 'npm run itest'
}
}
stage('Integration tests') {
sh 'DEBUG=testcontainers:* npm run itest'
}
}
/*
stage('Down') {
sh './docker/test/down.sh'
}
*/
}
2 changes: 1 addition & 1 deletion docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ COPY src src

RUN npm ci

ENTRYPOINT [ "npm", "run", "deploy:all" ]
ENTRYPOINT [ "npm", "run", "deploy:all" ]
2 changes: 1 addition & 1 deletion docker/test/.env
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ DATA=/home/tmp/graph-test
DB_USER=graphnode
DB_PASSWORD=somerandompasswordthatishardtoguess
DB_NAME=graphnode-db
NETWORK_NAME=test
NETWORK_NAME=test
2 changes: 1 addition & 1 deletion docker/test/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ services:
# - 8546
ports:
- 8545:8545
# - 8546:8546
# - 8546:8546 # port (not required for integrations tests) fails to open on CI

ipfs:
restart: unless-stopped
Expand Down
3 changes: 0 additions & 3 deletions docker/test/down.sh

This file was deleted.

5 changes: 0 additions & 5 deletions docker/test/up.sh

This file was deleted.

82 changes: 46 additions & 36 deletions itest/integration.test.ts
Original file line number Diff line number Diff line change
@@ -1,44 +1,54 @@
import { ApolloClient, InMemoryCache, gql } from '@apollo/client';
import assert from 'assert';
import { ApolloClient, gql, InMemoryCache } from '@apollo/client';
import { equal } from 'assert';
import { DockerComposeEnvironment, Wait } from 'testcontainers';

const SECONDS = 1000;
const MINUTES = 60 * SECONDS;
const APIURL = 'http://localhost:8000/subgraphs/name/test/poco';
const client = new ApolloClient({
uri: APIURL,
cache: new InMemoryCache(),
});

async function main() {
console.log('Running integration tests..');
const environment = new DockerComposeEnvironment('docker/test/', 'docker-compose.yml')
.withStartupTimeout(3 * 60 * 1000)
.withWaitStrategy(
'poco-subgraph-deployer-1',
Wait.forLogMessage(
'Deployed to http://graphnode:8000/subgraphs/name/test/poco/graphql',
),
describe('Integration tests', () => {
/**
* Services are started only once before running all tests to get a decent test
* time in case of multiple tests. Please switch to `beforeEach` if necessary.
* Shutdown of services is handled by `testcontainers` framework.
*/
before(async () => {
console.log('Starting services..');
const environment = new DockerComposeEnvironment('docker/test/', 'docker-compose.yml')
.withStartupTimeout(3 * MINUTES)
.withWaitStrategy(
'poco-subgraph-deployer-1',
Wait.forLogMessage(
'Deployed to http://graphnode:8000/subgraphs/name/test/poco/graphql',
),
);
await environment.up();
const secondsToWait = 5;
console.log(
`Waiting ${secondsToWait}s for graphnode to ingest a few blocks before querying it..`,
);
await environment.up();
// Wait for graphnode to ingest a few blocks before querying it
const secondsToWait = 5;
console.log(`Waiting ${secondsToWait}s..`);
await new Promise((resolve) => {
return setTimeout(resolve, secondsToWait * 1000);
await new Promise((resolve) => {
return setTimeout(resolve, secondsToWait * SECONDS);
});
});
const client = new ApolloClient({
uri: APIURL,
cache: new InMemoryCache(),
});
const result = await client.query({
query: gql(`
query {
protocol(id: "iExec") {
tvl
id

it('should get protocol', async () => {
const result = await client.query({
query: gql(`
query {
protocol(id: "iExec") {
id
tvl
}
}
}
`),
`),
});
const protocol = result.data.protocol;
equal(protocol.id, 'iExec');
equal(protocol.tvl, '0.02025');
});
const protocol = result.data.protocol;
assert.equal(protocol.id, 'iExec');
assert.equal(protocol.tvl, '0.02025');
console.log('Completed integration tests ✔️');
}

main();
});
Loading

0 comments on commit 852f818

Please sign in to comment.