From e20d811c29491b143f5006e0980dd589fed4eed4 Mon Sep 17 00:00:00 2001 From: "harshitha.d" Date: Thu, 3 Apr 2025 12:36:14 +0530 Subject: [PATCH 1/5] Add environment variable checks and refactor live preview tests --- test/config.js | 14 +++++++ test/live-preview/live-preview-test.js | 52 ++++++++------------------ 2 files changed, 29 insertions(+), 37 deletions(-) diff --git a/test/config.js b/test/config.js index 69c45db8..33e60ab5 100755 --- a/test/config.js +++ b/test/config.js @@ -1,6 +1,20 @@ 'use strict'; require('dotenv').config() +const requiredVars = ['API_KEY', 'DELIVERY_TOKEN', 'ENVIRONMENT', 'HOST']; +const missingVars = requiredVars.filter((key) => !process.env[key]); + +if (missingVars.length > 0) { + const errorMessage = `\x1b[31mError: Missing environment variables - ${missingVars.join(', ')}`; + + if (process.env.NODE_ENV === 'test' || process.env.JEST_WORKER_ID !== undefined) { + throw new Error(errorMessage); + } else { + console.error(errorMessage); + process.exit(1); + } +} + module.exports = { stack: { 'api_key': process.env.API_KEY, 'delivery_token': process.env.DELIVERY_TOKEN, 'environment': process.env.ENVIRONMENT, }, host: process.env.HOST, diff --git a/test/live-preview/live-preview-test.js b/test/live-preview/live-preview-test.js index 4ffc93e2..6685e8cb 100644 --- a/test/live-preview/live-preview-test.js +++ b/test/live-preview/live-preview-test.js @@ -1,11 +1,13 @@ 'use strict'; +const init = require("../config.js"); const Contentstack = require('../../dist/node/contentstack.js'); describe('Contentstack Live Preview Tests', () => { test('should check for values initialized', () => { + const stack1 = Contentstack.Stack(init.stack) const stack = Contentstack.Stack({ - 'api_key': process.env.region_API_KEY, + 'api_key': process.env.API_KEY, 'delivery_token': process.env.DELIVERY_TOKEN, 'environment': process.env.ENVIRONMENT }); @@ -16,15 +18,9 @@ describe('Contentstack Live Preview Tests', () => { }); test('should check host when live preview is enabled and management token is provided', () => { - const stack = Contentstack.Stack({ - 'api_key': process.env.API_KEY, - 'delivery_token': process.env.DELIVERY_TOKEN, - 'environment': process.env.ENVIRONMENT, - live_preview: { - enable: true, - management_token: 'management_token' - } - }); + init.stack.live_preview.enable = true; + init.stack.live_preview.management_token = 'management_token'; + const stack = Contentstack.Stack(init.stack); const livePreviewObject = stack.config.live_preview; expect(livePreviewObject).not.toBe('undefined'); @@ -34,15 +30,9 @@ describe('Contentstack Live Preview Tests', () => { }); test('should check host when live preview is disabled and management token is provided', () => { - const stack = Contentstack.Stack({ - 'api_key': process.env.API_KEY, - 'delivery_token': process.env.DELIVERY_TOKEN, - 'environment': process.env.ENVIRONMENT, - live_preview: { - enable: false, - management_token: 'management_token' - } - }); + init.stack.live_preview.enable = false; + init.stack.live_preview.management_token = 'management_token'; + const stack = Contentstack.Stack(init.stack); const livePreviewObject = stack.config.live_preview; expect(livePreviewObject).not.toBe('undefined'); @@ -51,15 +41,9 @@ describe('Contentstack Live Preview Tests', () => { }); test('should check host when live preview is enabled and preview token is provided', () => { - const stack = Contentstack.Stack({ - 'api_key': process.env.API_KEY, - 'delivery_token': process.env.DELIVERY_TOKEN, - 'environment': process.env.ENVIRONMENT, - live_preview: { - enable: true, - preview_token: 'preview_token' - } - }); + init.stack.live_preview.enable = true; + init.stack.live_preview.preview_token = 'preview_token'; + const stack = Contentstack.Stack(init.stack); const livePreviewObject = stack.config.live_preview; expect(livePreviewObject).not.toBe('undefined'); @@ -70,15 +54,9 @@ describe('Contentstack Live Preview Tests', () => { }); test('should check host when live preview is disabled and preview token is provided', () => { - const stack = Contentstack.Stack({ - 'api_key': process.env.API_KEY, - 'delivery_token': process.env.DELIVERY_TOKEN, - 'environment': process.env.ENVIRONMENT, - live_preview: { - enable: false, - preview_token: 'preview_token' - } - }); + init.stack.live_preview.enable = false; + init.stack.live_preview.preview_token = 'preview_token'; + const stack = Contentstack.Stack(init.stack); const livePreviewObject = stack.config.live_preview; expect(livePreviewObject).not.toBe('undefined'); From 68d409084153088c3b4cc1120b7d9e974aa327ff Mon Sep 17 00:00:00 2001 From: "harshitha.d" Date: Tue, 8 Apr 2025 13:19:32 +0530 Subject: [PATCH 2/5] Update environment variable checks and improve error handling in config --- test/config.js | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/test/config.js b/test/config.js index 33e60ab5..6f5088f2 100755 --- a/test/config.js +++ b/test/config.js @@ -1,18 +1,14 @@ 'use strict'; -require('dotenv').config() +require('dotenv').config(); -const requiredVars = ['API_KEY', 'DELIVERY_TOKEN', 'ENVIRONMENT', 'HOST']; +const requiredVars = ['HOST', 'EMAIL', 'PASSWORD', 'ORGANIZATION', 'API_KEY']; const missingVars = requiredVars.filter((key) => !process.env[key]); if (missingVars.length > 0) { const errorMessage = `\x1b[31mError: Missing environment variables - ${missingVars.join(', ')}`; - - if (process.env.NODE_ENV === 'test' || process.env.JEST_WORKER_ID !== undefined) { - throw new Error(errorMessage); - } else { - console.error(errorMessage); - process.exit(1); - } + const error = new Error(errorMessage); + error.stack = error.message; + throw error; } module.exports = { From 7a6deb2ec9f1d8ea8e7fafff42ffc25fed860c2a Mon Sep 17 00:00:00 2001 From: "harshitha.d" Date: Tue, 8 Apr 2025 13:27:57 +0530 Subject: [PATCH 3/5] Bump version to 3.25.3 and update changelog to handle sanity tests without provided ENVs --- CHANGELOG.md | 5 +++++ package-lock.json | 4 ++-- package.json | 2 +- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2c11ea9d..7b0bb633 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ ## Change log +### Version: 3.25.3 +#### Date: April-14-2025 +##### Fix: + - Handle the sanity tests when ENVs are not provided + ### Version: 3.25.2 #### Date: April-02-2025 ##### Fix: diff --git a/package-lock.json b/package-lock.json index b9fd17b6..5f81ba35 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "contentstack", - "version": "3.25.2", + "version": "3.25.3", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "contentstack", - "version": "3.25.2", + "version": "3.25.3", "license": "MIT", "dependencies": { "@contentstack/utils": "^1.3.18", diff --git a/package.json b/package.json index a3427ed2..4a5b1dd2 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "contentstack", - "version": "3.25.2", + "version": "3.25.3", "description": "Contentstack Javascript SDK", "homepage": "https://www.contentstack.com/", "author": { From d4abca6b2b8dd1b0d1ff8c93d5958c3e145799d1 Mon Sep 17 00:00:00 2001 From: "harshitha.d" Date: Tue, 8 Apr 2025 13:36:33 +0530 Subject: [PATCH 4/5] Update changelog date for version 3.25.3 --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7b0bb633..1b2bd660 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,7 @@ ## Change log ### Version: 3.25.3 -#### Date: April-14-2025 +#### Date: April-21-2025 ##### Fix: - Handle the sanity tests when ENVs are not provided From 0de85002c8426d0f7d9275adb306718bc5f0659d Mon Sep 17 00:00:00 2001 From: "harshitha.d" Date: Tue, 8 Apr 2025 13:44:17 +0530 Subject: [PATCH 5/5] Update integrity hashes in README --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 5dffec71..3471eda5 100755 --- a/README.md +++ b/README.md @@ -19,11 +19,11 @@ For browsers, we recommend to download the library via npm or yarn to ensure 100 If you'd like to use a standalone built file you can use the following script tag or download it from [jsDelivr](https://www.jsdelivr.com/package/npm/contentstack), under the `dist` directory: ```html - + ``` You can also specify a specific version number. ```html - + ``` To initialize the SDK, you will need to specify the API Key, Delivery Token, and Environment Name of your stack.