Skip to content

Commit

Permalink
Merge pull request #1210 from bigmontz/fix-npm-test
Browse files Browse the repository at this point in the history
Fix `npm test` when running test containers
  • Loading branch information
MaxAake authored Aug 12, 2024
2 parents 7ffa4af + b2ca1d4 commit bb5687e
Showing 1 changed file with 54 additions and 35 deletions.
89 changes: 54 additions & 35 deletions packages/neo4j-driver-deno/test/neo4j.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
}

}
})

0 comments on commit bb5687e

Please sign in to comment.