Skip to content

Fix npm test when running test containers #1210

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 })
}

}
})