From b2ca1d4804fa3d247cd2d0e06fe3460dde6e25b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antonio=20Barc=C3=A9los?= Date: Fri, 9 Aug 2024 14:49:41 +0200 Subject: [PATCH] Fix `npm test` when running test containers The tests were failing because Deno integration tests can't access a database. The problem happens because tests are using `TestContainers` by default and Deno doesn't have support for it yet. So, the problem is circuvented by skipping the Deno integration tests for the case we are using `testcontainers`. This is not a big issue since, 1. Pipelines and testkit doesn't make use of testcontainers, so the tests will not be skipped in important places. 2. The amount of testing scenarios are quite small and not likely to change in behaviour. --- packages/neo4j-driver-deno/test/neo4j.test.ts | 89 +++++++++++-------- 1 file changed, 54 insertions(+), 35 deletions(-) diff --git a/packages/neo4j-driver-deno/test/neo4j.test.ts b/packages/neo4j-driver-deno/test/neo4j.test.ts index e682dac20..c673e853a 100644 --- a/packages/neo4j-driver-deno/test/neo4j.test.ts +++ b/packages/neo4j-driver-deno/test/neo4j.test.ts @@ -27,58 +27,77 @@ const scheme = env.TEST_NEO4J_SCHEME || 'bolt' const boltPort = env.TEST_NEO4J_BOLT_PORT || 7687 const uri = `${scheme}://${hostname}:${boltPort}` const authToken = neo4j.auth.basic(username, password) +const testContainersDisabled = env.TEST_CONTAINERS_DISABLED !== undefined + ? env.TEST_CONTAINERS_DISABLED.toUpperCase() === 'TRUE' + : false // Deno will fail with resource leaks -Deno.test('neo4j.driver should be able to use explicity resource management', async () => { - await using driver = neo4j.driver(uri, authToken) +Deno.test({ + name: 'neo4j.driver should be able to use explicity resource management', + ignore: !testContainersDisabled, + async fn() { + await using driver = neo4j.driver(uri, authToken) - await driver.executeQuery('RETURN 1') -}) - -// Deno will fail with resource leaks -Deno.test('driver.session should be able to use explicity resource management', async () => { - await using driver = neo4j.driver(uri, authToken) - await using session = driver.session() - - await session.executeRead(tx => "RETURN 1") + await driver.executeQuery('RETURN 1') + } }) - // Deno will fail with resource leaks -Deno.test('session.beginTransaction should rollback the transaction if not committed', async () => { - await using driver = neo4j.driver(uri, authToken) - await using session = driver.session() - const name = "Must Be Conor" +Deno.test({ + name: 'driver.session should be able to use explicity resource management', + ignore: !testContainersDisabled, + async fn() { + await using driver = neo4j.driver(uri, authToken) + await using session = driver.session() + await session.executeRead(tx => "RETURN 1") - { - await using tx = session.beginTransaction() - await tx.run('CREATE (p:Person { name:$name }) RETURN p', { name }).summary() } - - const { records } = await driver.executeQuery('MATCH (p:Person { name:$name }) RETURN p', { name }) - assertEquals(records.length, 0) }) - // Deno will fail with resource leaks -Deno.test('session.beginTransaction should noop if resource committed', async () => { - await using driver = neo4j.driver(uri, authToken) - const name = "Must Be Conor" - - try { +Deno.test({ + name: 'session.beginTransaction should rollback the transaction if not committed', + ignore: !testContainersDisabled, + async fn() { + await using driver = neo4j.driver(uri, authToken) await using session = driver.session() - + const name = "Must Be Conor" + { await using tx = session.beginTransaction() await tx.run('CREATE (p:Person { name:$name }) RETURN p', { name }).summary() - await tx.commit() } - + const { records } = await driver.executeQuery('MATCH (p:Person { name:$name }) RETURN p', { name }) - assertEquals(records.length, 1) - } finally { - // cleaning up - await driver.executeQuery('MATCH (p:Person { name:$name }) DELETE(p)', { name }) + assertEquals(records.length, 0) + } +}) + + +// Deno will fail with resource leaks +Deno.test({ + name: 'session.beginTransaction should noop if resource committed', + ignore: !testContainersDisabled, + async fn() { + await using driver = neo4j.driver(uri, authToken) + const name = "Must Be Conor" + + try { + await using session = driver.session() + + { + await using tx = session.beginTransaction() + await tx.run('CREATE (p:Person { name:$name }) RETURN p', { name }).summary() + await tx.commit() + } + + const { records } = await driver.executeQuery('MATCH (p:Person { name:$name }) RETURN p', { name }) + assertEquals(records.length, 1) + } finally { + // cleaning up + await driver.executeQuery('MATCH (p:Person { name:$name }) DELETE(p)', { name }) + } + } })