11const path = require ( 'path' ) ;
2- const mock = require ( 'mock-fs' ) ;
32const assert = require ( "assert" ) ;
43const sinon = require ( "sinon" ) ;
54const fs = require ( 'fs' ) ;
@@ -11,35 +10,21 @@ const TEST_CLOUD_NAME = require('../../testUtils/testConstants').TEST_CLOUD_NAME
1110describe ( 'SDK url analytics' , ( ) => {
1211 let processVersions = { } ;
1312
14- before ( ( ) => {
13+ beforeEach ( ( ) => {
1514 cloudinary . config ( true ) ; // reset
16-
17- processVersions = process . versions ;
18- delete process . versions ;
19- } ) ;
20-
21- after ( ( ) => {
22- process . versions = processVersions ;
15+ cloudinary . config ( {
16+ techVersion : '12.0.0'
17+ } ) ;
2318 } ) ;
2419
2520 describe ( 'when package json is available' , ( ) => {
26- before ( ( ) => {
27- const file = path . join ( __dirname , '../../../package.json' ) ;
28-
29- mock ( {
30- [ file ] : '{"version":"1.24.0"}'
21+ beforeEach ( ( ) => {
22+ cloudinary . config ( {
23+ sdkSemver : '1.24.0'
3124 } ) ;
3225 } ) ;
3326
34- after ( ( ) => {
35- mock . restore ( ) ;
36- } ) ;
37-
3827 it ( 'can be turned off via options' , ( ) => {
39- process . versions = {
40- node : '12.0.0'
41- } ;
42-
4328 const imgStr = cloudinary . image ( "hello" , {
4429 format : "png" ,
4530 analytics : false
@@ -49,10 +34,6 @@ describe('SDK url analytics', () => {
4934 } ) ;
5035
5136 it ( 'defaults to true even if analytics is not passed as an option' , ( ) => {
52- process . versions = {
53- node : '12.0.0'
54- } ;
55-
5637 const imgStr = cloudinary . image ( "hello" , {
5738 format : "png"
5839 } ) ;
@@ -61,10 +42,6 @@ describe('SDK url analytics', () => {
6142 } ) ;
6243
6344 it ( 'reads from process.versions and package.json (Mocked)' , ( ) => {
64- process . versions = {
65- node : '12.0.0'
66- } ;
67-
6845 const imgStr = cloudinary . image ( "hello" , {
6946 format : "png" ,
7047 analytics : true
@@ -74,12 +51,8 @@ describe('SDK url analytics', () => {
7451 } ) ;
7552
7653 it ( 'reads from process.versions and package.json (Mocked) - Responsive' , ( ) => {
77- process . versions = {
78- node : '12.0.0'
79- } ;
80-
8154 const imgStr = cloudinary . image ( "hello" , {
82- format : " png" ,
55+ format : ' png' ,
8356 responsive : true ,
8457 analytics : true
8558 } ) ;
@@ -88,9 +61,7 @@ describe('SDK url analytics', () => {
8861 } ) ;
8962
9063 it ( 'reads from tracked analytics configuration' , ( ) => {
91- process . versions = {
92- node : '12.0.0'
93- } ;
64+ cloudinary . config ( true ) ; // reset
9465
9566 const imgStr = cloudinary . image ( "hello" , {
9667 format : "png" ,
@@ -105,10 +76,6 @@ describe('SDK url analytics', () => {
10576 } ) ;
10677
10778 it ( 'should still accept analytics param passed as camel case' , ( ) => {
108- process . versions = {
109- node : '12.0.0'
110- } ;
111-
11279 const imgStr = cloudinary . image ( "hello" , {
11380 format : "png" ,
11481 urlAnalytics : true ,
@@ -123,10 +90,6 @@ describe('SDK url analytics', () => {
12390
12491 describe ( 'with two different casings' , ( ) => {
12592 it ( 'should treat camel case analytics param as more important than snake case' , ( ) => {
126- process . versions = {
127- node : '12.0.0'
128- } ;
129-
13093 const imgStr1 = cloudinary . image ( "hello" , {
13194 format : "png" ,
13295 urlAnalytics : true ,
@@ -157,17 +120,15 @@ describe('SDK url analytics', () => {
157120 const enoent = new Error ( 'ENOENT' ) ;
158121 enoent . code = 'ENOENT' ;
159122 sinon . stub ( fs , 'readFileSync' ) . throws ( enoent ) ;
123+
124+ cloudinary . config ( true ) ; // reset
160125 } ) ;
161126
162127 after ( ( ) => {
163128 sinon . restore ( ) ;
164129 } ) ;
165130
166131 it ( 'uses 0.0.0 as fallback sdk semver' , ( ) => {
167- process . versions = {
168- node : '12.0.0'
169- } ;
170-
171132 const urlWithToken = cloudinary . url ( "hello" , {
172133 format : "png" ,
173134 analytics : true
0 commit comments