Add embryo to e2e tests
This commit is contained in:
@@ -0,0 +1,4 @@
|
|||||||
|
module.exports = {
|
||||||
|
preset: 'ts-jest',
|
||||||
|
testEnvironment: 'node',
|
||||||
|
};
|
||||||
Generated
+3800
File diff suppressed because it is too large
Load Diff
+9
-8
@@ -4,7 +4,9 @@
|
|||||||
"description": "",
|
"description": "",
|
||||||
"main": "src/index.js",
|
"main": "src/index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "nodemon -w src --ext ts --exec ts-node src/index.ts"
|
"start": "nodemon -w src --ext ts --exec ts-node src/index.ts",
|
||||||
|
"test": "jest --detectOpenHandles",
|
||||||
|
"test:dev": "jest --watch"
|
||||||
},
|
},
|
||||||
"author": "",
|
"author": "",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
@@ -12,6 +14,7 @@
|
|||||||
"apollo-datasource": "^0.8.0",
|
"apollo-datasource": "^0.8.0",
|
||||||
"apollo-datasource-rest": "^0.11.0",
|
"apollo-datasource-rest": "^0.11.0",
|
||||||
"apollo-server": "^2.22.2",
|
"apollo-server": "^2.22.2",
|
||||||
|
"async-redis": "^1.1.7",
|
||||||
"datasource-sql": "^1.4.0",
|
"datasource-sql": "^1.4.0",
|
||||||
"dotenv": "^8.2.0",
|
"dotenv": "^8.2.0",
|
||||||
"graphql": "^15.5.0",
|
"graphql": "^15.5.0",
|
||||||
@@ -27,16 +30,14 @@
|
|||||||
"validator": "^13.5.2"
|
"validator": "^13.5.2"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"@types/jest": "^26.0.22",
|
||||||
"@typescript-eslint/eslint-plugin": "^4.21.0",
|
"@typescript-eslint/eslint-plugin": "^4.21.0",
|
||||||
"@typescript-eslint/parser": "^4.21.0",
|
"@typescript-eslint/parser": "^4.21.0",
|
||||||
"eslint": "^7.23.0",
|
"eslint": "^7.23.0",
|
||||||
"eslint-config-prettier": "^8.1.0",
|
"eslint-config-prettier": "^8.1.0",
|
||||||
"eslint-plugin-prettier": "^3.3.1"
|
"eslint-plugin-prettier": "^3.3.1",
|
||||||
},
|
"jest": "^26.6.3",
|
||||||
"jest": {
|
"testcontainers": "^7.7.0",
|
||||||
"testPathIgnorePatterns": [
|
"ts-jest": "^26.5.5"
|
||||||
"/node_modules/",
|
|
||||||
"/__utils"
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,71 @@
|
|||||||
|
import fs from 'fs';
|
||||||
|
import { resolve } from 'path';
|
||||||
|
|
||||||
|
import { GenericContainer, StartedTestContainer } from 'testcontainers';
|
||||||
|
import Knex from 'knex';
|
||||||
|
import knexTinyLogger from 'knex-tiny-logger';
|
||||||
|
|
||||||
|
jest.setTimeout(18000_000);
|
||||||
|
|
||||||
|
const createKnexDb = (mappedPort: string, database: string) => {
|
||||||
|
const db = Knex({
|
||||||
|
client: 'pg',
|
||||||
|
connection: `postgresql://testuser:test@localhost:${mappedPort}/${database}`,
|
||||||
|
pool: { min: 0 },
|
||||||
|
});
|
||||||
|
knexTinyLogger(db);
|
||||||
|
return db;
|
||||||
|
};
|
||||||
|
|
||||||
|
const createDB = async (mappedPort): Promise<Knex> => {
|
||||||
|
const initialDb = createKnexDb(mappedPort, 'postgres');
|
||||||
|
await initialDb.raw('CREATE DATABASE photowalltest');
|
||||||
|
await initialDb.destroy();
|
||||||
|
|
||||||
|
const db = createKnexDb(mappedPort, 'photowalltest');
|
||||||
|
const sql = fs.readFileSync(resolve(__dirname, 'seed.sql')).toString();
|
||||||
|
await db.raw(sql);
|
||||||
|
return db;
|
||||||
|
};
|
||||||
|
|
||||||
|
const openTestContainer = async (): Promise<StartedTestContainer> => {
|
||||||
|
const container = await new GenericContainer('postgres')
|
||||||
|
.withEnv('POSTGRES_USER', 'testuser')
|
||||||
|
.withEnv('POSTGRES_PASSWORD', 'test')
|
||||||
|
.withEnv('POSTGRES_DB', 'apidb')
|
||||||
|
.withExposedPorts(5432)
|
||||||
|
.start();
|
||||||
|
|
||||||
|
// const stream = await container.logs();
|
||||||
|
// stream
|
||||||
|
// .on('data', (line) => console.debug(line))
|
||||||
|
// .on('err', (line) => console.error(line))
|
||||||
|
// .on('end', () => console.debug('Docker Container Stream closed...'));
|
||||||
|
|
||||||
|
return container;
|
||||||
|
};
|
||||||
|
|
||||||
|
function sleep(ms) {
|
||||||
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
||||||
|
}
|
||||||
|
|
||||||
|
describe('GenericContainer', () => {
|
||||||
|
let container: StartedTestContainer;
|
||||||
|
let db: Knex;
|
||||||
|
|
||||||
|
beforeAll(async () => {
|
||||||
|
container = await openTestContainer();
|
||||||
|
db = await createDB(container.getMappedPort(5432));
|
||||||
|
});
|
||||||
|
|
||||||
|
afterAll(async () => {
|
||||||
|
await container.stop();
|
||||||
|
await db.destroy();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('works', async () => {
|
||||||
|
const res = await db.raw('select now()');
|
||||||
|
expect(res.rows[0]['now']).toBeInstanceOf(Date);
|
||||||
|
await sleep(2000000);
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
CREATE EXTENSION IF NOT EXISTS unaccent WITH SCHEMA public;
|
||||||
|
CREATE TABLE locales (
|
||||||
|
id integer NOT NULL,
|
||||||
|
value character(5),
|
||||||
|
esales_locale character varying NOT NULL,
|
||||||
|
fallback_id integer,
|
||||||
|
name text NOT NULL
|
||||||
|
);
|
||||||
|
CREATE TABLE markets (
|
||||||
|
id integer NOT NULL,
|
||||||
|
name character varying,
|
||||||
|
locale_id integer
|
||||||
|
);
|
||||||
|
CREATE TABLE market_locales (
|
||||||
|
id integer NOT NULL,
|
||||||
|
market_id integer NOT NULL,
|
||||||
|
locale_id integer NOT NULL,
|
||||||
|
name text NOT NULL
|
||||||
|
);
|
||||||
Reference in New Issue
Block a user