Skip to content

Commit

Permalink
fix e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nicholascus committed Jan 4, 2024
1 parent 992fc86 commit bb013cc
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 8 deletions.
22 changes: 22 additions & 0 deletions e2e/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
version: '3.8'

services:
mongodb:
image: mongodb/mongodb-community-server:6.0-ubi8
ports:
- 27017

playwright:
image: mcr.microsoft.com/playwright:v1.40.1-focal
volumes:
- ../:/app
environment:
- CONFIG_FILE=test-config.docker-compose.json
- MONGO_SERVER_ADDRESS=mongodb:27017
working_dir: /app
command: bash -c "while true; do sleep 10000; done"
depends_on:
- mongodb

volumes:
mongodb_data:
13 changes: 8 additions & 5 deletions e2e/e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ function startServer(

let client: MongoClient;
async function getMongoClient() {
const connectionString: string = 'mongodb://127.0.0.1:27017/test-bopilot';
const connectionString: string = `mongodb://${process.env.MONGO_SERVER_ADDRESS ?? '127.0.0.1:27017'}/test-bopilot`;
if (!client) {
client = await MongoClient.connect(connectionString);
}
Expand Down Expand Up @@ -88,7 +88,7 @@ describe('End-to-End Test', () => {
args: [`--remote-debugging-port=${browserCdpPort}`],
headless: true,
});
loadJsonConfig(path.resolve(__dirname, 'test-config.json'));
loadJsonConfig(path.resolve(__dirname, `${process.env.CONFIG_FILE ?? 'test-config.json'}`));
parsingServer = new Bootstrap().run(browserCdpPort);
});

Expand All @@ -102,17 +102,19 @@ describe('End-to-End Test', () => {
client.db().collection('data').deleteMany({});

page = await browser.newPage();
await page.goto(`http://localhost:${port}/index.html`);
await page.goto(`http://127.0.0.1:${port}/index.html`);
});

afterEach(async () => {
await page.close();
});

it('should have 5 elements on the page before scrolling', async () => {
it('should have test page available in the browser', async () => {
const title = await page.title();
expect(title).toBe('Content Parsing Test'); // <-- we are on the right page
expect(title).toBe('Content Parsing Test');
});

it('should have 5 elements on the page before scrolling', async () => {
expect(
await waitUntil(
async function () {
Expand Down Expand Up @@ -148,4 +150,5 @@ describe('End-to-End Test', () => {
),
).toBe(true);
});

});
24 changes: 24 additions & 0 deletions e2e/test-config.docker-compose.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"parsers": [{ "parser": "TestParser", "logger": "MongoDbWriter" }],
"sourceDirs": ["e2e/test-parser"],
"components": [
{
"name": "MongoDbWriter",
"config": [
{
"param": "connection_string",
"value": "mongodb://mongodb:27017/test-bopilot"
}
]
},
{
"name": "TestParser",
"config": [
{
"param": "url",
"value": "http://127.0.0.1:8080"
}
]
}
]
}
2 changes: 1 addition & 1 deletion e2e/test-config.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"parsers": [{ "parser": "TestParser", "logger": "MongoDbWriter" }],
"sourceDirs": ["/Users/niko/dev/playwright-copilot-plain/e2e/test-parser"],
"sourceDirs": ["e2e/test-parser"],
"components": [
{
"name": "MongoDbWriter",
Expand Down
3 changes: 2 additions & 1 deletion src/engine/ComponentLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export default class ComponentLoader {
errors.push(error);
}
}
console.log(paths);
throw Error(`Error instantiating class: ${className}, ${path}`);
}

Expand All @@ -40,7 +41,7 @@ export default class ComponentLoader {
'.',
path.resolve(__dirname, '../parsers'),
path.resolve(__dirname, '../writers'),
...(config.sourceDirs ?? []),
...(config.sourceDirs.map(v => path.resolve(__dirname, '..', '..', v)) ?? []),
].map(v => `${v}/${fileName}`);
}

Expand Down
1 change: 0 additions & 1 deletion src/engine/__tests__/ComponentLoader.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// FILEPATH: /Users/niko/dev/playwright-copilot-plain/src/engine/__tests__/ComponentLoader.test.ts
import path from 'path';
import ComponentLoaderTestable from './ComponentLoaderTestable';
import { MockClass } from './mock-path/MockClass';
Expand Down

0 comments on commit bb013cc

Please sign in to comment.