diff --git a/index.js b/index.js index 3630144..8fb9db6 100644 --- a/index.js +++ b/index.js @@ -128,17 +128,27 @@ let hasNativeReservationSupportCache = null * @returns {boolean} True if native reservation supported */ function isNativeReservationSupported() { - if (process.env.DATAFORM_MOCK_NATIVE_RESERVATION === 'true') return true - if (process.env.DATAFORM_MOCK_NATIVE_RESERVATION === 'false') return false - if (hasNativeReservationSupportCache !== null) { return hasNativeReservationSupportCache } + if (process.env.DATAFORM_MOCK_NATIVE_RESERVATION === 'true') { + hasNativeReservationSupportCache = true + return true + } + if (process.env.DATAFORM_MOCK_NATIVE_RESERVATION === 'false') { + hasNativeReservationSupportCache = false + return false + } + hasNativeReservationSupportCache = false return false } +function resetNativeReservationSupportCache() { + hasNativeReservationSupportCache = null +} + /** * Helper to check if a query/array of queries has an outer DECLARE statement * @param {string|string[]|Function} sql - The SQL statement(s) to check @@ -376,5 +386,6 @@ module.exports = { prependStatement, isArrayOrString, findReservation, - isNativeReservationSupported + isNativeReservationSupported, + resetNativeReservationSupportCache } diff --git a/test/index.test.js b/test/index.test.js index 1610b1b..f6770b4 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -2,7 +2,8 @@ const { createReservationSetter, getActionName, autoAssignActions, - isNativeReservationSupported + isNativeReservationSupported, + resetNativeReservationSupportCache } = require('../index') /** @@ -63,6 +64,10 @@ describe('Dataform package', () => { process.env.DATAFORM_MOCK_NATIVE_RESERVATION = 'false' }) + beforeEach(() => { + resetNativeReservationSupportCache() + }) + afterAll(() => { process.env.DATAFORM_MOCK_NATIVE_RESERVATION = originalEnv }) @@ -223,6 +228,7 @@ describe('Dataform package', () => { beforeEach(() => { originalEnv = process.env.DATAFORM_MOCK_NATIVE_RESERVATION originalDataform = global.dataform + resetNativeReservationSupportCache() }) afterEach(() => { @@ -269,6 +275,10 @@ describe('Dataform package', () => { process.env.DATAFORM_MOCK_NATIVE_RESERVATION = 'false' }) + beforeEach(() => { + resetNativeReservationSupportCache() + }) + afterAll(() => { process.env.DATAFORM_MOCK_NATIVE_RESERVATION = originalEnv }) @@ -427,6 +437,7 @@ describe('Dataform package', () => { describe(`with native support = ${isNative}`, () => { beforeEach(() => { process.env.DATAFORM_MOCK_NATIVE_RESERVATION = String(isNative) + resetNativeReservationSupportCache() }) test('should apply reservations to existing publish actions', () => {