Skip to content

Commit e8a4541

Browse files
Merge pull request #325 from contentstack/fix/dx-2231-handle-envs
dx | 2231 handle envs
2 parents 2e70392 + 0de8500 commit e8a4541

File tree

6 files changed

+36
-43
lines changed

6 files changed

+36
-43
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
## Change log
22

3+
### Version: 3.25.3
4+
#### Date: April-21-2025
5+
##### Fix:
6+
- Handle the sanity tests when ENVs are not provided
7+
38
### Version: 3.25.2
49
#### Date: April-02-2025
510
##### Fix:

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ For browsers, we recommend to download the library via npm or yarn to ensure 100
1919
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:
2020

2121
```html
22-
<script src="https://cdn.jsdelivr.net/npm/contentstack@latest/dist/web/contentstack.min.js" integrity="9u29niwIJG3dEc7vPUc1ZA1Dl/uaiR4+s7k55kb/CCkzTzyFuZHNM165BQ10+Hiw%" crossorigin="anonymous"></script>
22+
<script src="https://cdn.jsdelivr.net/npm/contentstack@latest/dist/web/contentstack.min.js" integrity="12nVcFP1kBh/0Q5rLUvKE34exDRK2DpHUFkGkhRSXTcwGC2PI1D9h64C5arpt5OY" crossorigin="anonymous"></script>
2323
```
2424
You can also specify a specific version number.
2525
```html
26-
<script src="https://cdn.jsdelivr.net/npm/contentstack@3.20.3/dist/web/contentstack.min.js" integrity="9u29niwIJG3dEc7vPUc1ZA1Dl/uaiR4+s7k55kb/CCkzTzyFuZHNM165BQ10+Hiw%" crossorigin="anonymous"></script>
26+
<script src="https://cdn.jsdelivr.net/npm/contentstack@3.25.2/dist/web/contentstack.min.js" integrity="fXmq+b/kd2EenBR7APjzzy0hLTOhAhrir3C6HZYZKuF9O+g+HuSIU7Usi8Ccy9I5" crossorigin="anonymous"></script>
2727
```
2828

2929
To initialize the SDK, you will need to specify the API Key, Delivery Token, and Environment Name of your stack.

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "contentstack",
3-
"version": "3.25.2",
3+
"version": "3.25.3",
44
"description": "Contentstack Javascript SDK",
55
"homepage": "https://www.contentstack.com/",
66
"author": {

test/config.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
'use strict';
2-
require('dotenv').config()
2+
require('dotenv').config();
3+
4+
const requiredVars = ['HOST', 'EMAIL', 'PASSWORD', 'ORGANIZATION', 'API_KEY'];
5+
const missingVars = requiredVars.filter((key) => !process.env[key]);
6+
7+
if (missingVars.length > 0) {
8+
const errorMessage = `\x1b[31mError: Missing environment variables - ${missingVars.join(', ')}`;
9+
const error = new Error(errorMessage);
10+
error.stack = error.message;
11+
throw error;
12+
}
313

414
module.exports = {
515
stack: { 'api_key': process.env.API_KEY, 'delivery_token': process.env.DELIVERY_TOKEN, 'environment': process.env.ENVIRONMENT, },

test/live-preview/live-preview-test.js

Lines changed: 15 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
'use strict';
2+
const init = require("../config.js");
23

34
const Contentstack = require('../../dist/node/contentstack.js');
45

56
describe('Contentstack Live Preview Tests', () => {
67
test('should check for values initialized', () => {
8+
const stack1 = Contentstack.Stack(init.stack)
79
const stack = Contentstack.Stack({
8-
'api_key': process.env.region_API_KEY,
10+
'api_key': process.env.API_KEY,
911
'delivery_token': process.env.DELIVERY_TOKEN,
1012
'environment': process.env.ENVIRONMENT
1113
});
@@ -16,15 +18,9 @@ describe('Contentstack Live Preview Tests', () => {
1618
});
1719

1820
test('should check host when live preview is enabled and management token is provided', () => {
19-
const stack = Contentstack.Stack({
20-
'api_key': process.env.API_KEY,
21-
'delivery_token': process.env.DELIVERY_TOKEN,
22-
'environment': process.env.ENVIRONMENT,
23-
live_preview: {
24-
enable: true,
25-
management_token: 'management_token'
26-
}
27-
});
21+
init.stack.live_preview.enable = true;
22+
init.stack.live_preview.management_token = 'management_token';
23+
const stack = Contentstack.Stack(init.stack);
2824

2925
const livePreviewObject = stack.config.live_preview;
3026
expect(livePreviewObject).not.toBe('undefined');
@@ -34,15 +30,9 @@ describe('Contentstack Live Preview Tests', () => {
3430
});
3531

3632
test('should check host when live preview is disabled and management token is provided', () => {
37-
const stack = Contentstack.Stack({
38-
'api_key': process.env.API_KEY,
39-
'delivery_token': process.env.DELIVERY_TOKEN,
40-
'environment': process.env.ENVIRONMENT,
41-
live_preview: {
42-
enable: false,
43-
management_token: 'management_token'
44-
}
45-
});
33+
init.stack.live_preview.enable = false;
34+
init.stack.live_preview.management_token = 'management_token';
35+
const stack = Contentstack.Stack(init.stack);
4636

4737
const livePreviewObject = stack.config.live_preview;
4838
expect(livePreviewObject).not.toBe('undefined');
@@ -51,15 +41,9 @@ describe('Contentstack Live Preview Tests', () => {
5141
});
5242

5343
test('should check host when live preview is enabled and preview token is provided', () => {
54-
const stack = Contentstack.Stack({
55-
'api_key': process.env.API_KEY,
56-
'delivery_token': process.env.DELIVERY_TOKEN,
57-
'environment': process.env.ENVIRONMENT,
58-
live_preview: {
59-
enable: true,
60-
preview_token: 'preview_token'
61-
}
62-
});
44+
init.stack.live_preview.enable = true;
45+
init.stack.live_preview.preview_token = 'preview_token';
46+
const stack = Contentstack.Stack(init.stack);
6347

6448
const livePreviewObject = stack.config.live_preview;
6549
expect(livePreviewObject).not.toBe('undefined');
@@ -70,15 +54,9 @@ describe('Contentstack Live Preview Tests', () => {
7054
});
7155

7256
test('should check host when live preview is disabled and preview token is provided', () => {
73-
const stack = Contentstack.Stack({
74-
'api_key': process.env.API_KEY,
75-
'delivery_token': process.env.DELIVERY_TOKEN,
76-
'environment': process.env.ENVIRONMENT,
77-
live_preview: {
78-
enable: false,
79-
preview_token: 'preview_token'
80-
}
81-
});
57+
init.stack.live_preview.enable = false;
58+
init.stack.live_preview.preview_token = 'preview_token';
59+
const stack = Contentstack.Stack(init.stack);
8260

8361
const livePreviewObject = stack.config.live_preview;
8462
expect(livePreviewObject).not.toBe('undefined');

0 commit comments

Comments
 (0)