Skip to content
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

Bump jest to latest version, remove objection-transactional-tests #44

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
20 changes: 0 additions & 20 deletions index.test.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,8 @@
/* eslint-env jest */
const bcrypt = require('bcrypt')
const { transactionPerTest } = require('objection-transactional-tests')
const { Model } = require('objection')
const Knex = require('knex')
const objectionPassword = require('./index')

// Set up knex
const knex = Knex({
client: 'sqlite3',
connection: {
filename: ':memory:'
},
useNullAsDefault: true
})

// Bind knex instance to objection
Model.knex(knex)

const ObjectionPassword = objectionPassword() // Mixin with default options.

// Objection model using default options
Expand All @@ -32,12 +18,6 @@ beforeAll(async () => {
table.string('name')
table.string('password')
})
transactionPerTest()
})

afterAll(async () => {
await knex.schema.dropTable('sample_model')
knex.destroy()
})

describe('$beforeInsert', () => {
Expand Down
4 changes: 4 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ module.exports = {
// The directory where Jest should output its coverage files
coverageDirectory: 'coverage',

// A list of paths to modules that run some code to configure or set up
// the testing framework before each test file in the suite is executed
setupFilesAfterEnv: ['./jest.setup.js'],

// The test environment that will be used for testing
testEnvironment: 'node'
}
33 changes: 33 additions & 0 deletions jest.setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
const Knex = require('knex')
const { transaction, Model } = require('objection')

global.beforeAll(async () => {
// Set up knex
const knex = Knex({
client: 'sqlite3',
connection: {
filename: ':memory:'
},
useNullAsDefault: true
})

// Bind knex instance to objection
Model.knex(knex)

global.knex = knex
global.txn = null
})

global.beforeEach(async () => {
global.txn = await transaction.start(knex)
Model.knex(global.txn)
})

global.afterEach(async () => {
await global.txn.rollback()
Model.knex(knex)
})

global.afterAll(async () => {
global.knex.destroy()
})
Loading