Skip to content

Commit a4d33d6

Browse files
committed
udpate test cases url generation
1 parent 2b7570a commit a4d33d6

File tree

5 files changed

+32
-45
lines changed

5 files changed

+32
-45
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"@babel/core": "^7.10.5",
1616
"@babel/preset-env": "^7.10.4",
1717
"@rollup/plugin-commonjs": "^14.0.0",
18+
"@rollup/plugin-json": "^4.1.0",
1819
"@rollup/plugin-node-resolve": "^8.4.0",
1920
"chai": "^4.2.0",
2021
"formdata-node": "2.1.0",
@@ -53,4 +54,4 @@
5354
"url": "https://github.com/imagekit-developer/imagekit-javascript/issues"
5455
},
5556
"homepage": "https://github.com/imagekit-developer/imagekit-javascript#readme"
56-
}
57+
}

rollup.config.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import babel from 'rollup-plugin-babel';
22
import resolve from '@rollup/plugin-node-resolve';
3+
import json from '@rollup/plugin-json';
34
import commonjs from '@rollup/plugin-commonjs';
45
import pkg from './package.json';
56
import { terser } from "rollup-plugin-terser";
@@ -15,6 +16,8 @@ export default [
1516
},
1617
plugins: [
1718
commonjs(), // so Rollup can convert `ms` to an ES module
19+
json(),
20+
terser()
1821
]
1922
},
2023
// CommonJS (for Node) and ES module (for bundlers) build.
@@ -28,6 +31,9 @@ export default [
2831
output: [
2932
{ file: pkg.main, format: 'cjs' },
3033
{ file: pkg.module, format: 'es' }
34+
],
35+
plugins: [
36+
json()
3137
]
3238
}
3339
];

src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { url } from "./url/index";
22
import { upload } from "./upload/index";
3-
const pkg = { version: "1.2.3" };
3+
import pkg from '../package.json';
44
import transformationUtils from "./utils/transformation"
55
import errorMessages from "./constants/errorMessages";
66

test/test.js

Lines changed: 16 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const sinon = require("sinon");
33
// const requestUtils = require('../src/utils/request.js');
44
const fs = require('fs');
55
const path = require('path');
6-
6+
const pkg = require("../package.json");
77
global.FormData = require('formdata-node');
88

99
const expect = chai.expect;
@@ -48,12 +48,8 @@ describe("Testing SDK", function () {
4848
"width" : "400"
4949
}]
5050
});
51-
52-
expect(url).to.match(/^https\:\/\/ik\.imagekit\.io\/test\_url\_endpoint\/[^\/]/);
53-
expect(url).to.match(new RegExp("[^\/]\/tr:"));
54-
expect(url).to.match(new RegExp(":h-300,w-400"));
55-
expect(url).to.match(/[^\/]\/test_path\.jpg[^\/][\?]?/);
56-
expect(url).to.match(/ik\-sdk\-version\=javascript\-\d\.\d\.\d/);
51+
52+
expect(url).equal(`https://ik.imagekit.io/test_url_endpoint/tr:h-300,w-400/test_path.jpg?ik-sdk-version=javascript-${pkg.version}`);
5753
});
5854

5955
it('should generate the correct url with path param with multiple leading slash', function() {
@@ -64,11 +60,8 @@ describe("Testing SDK", function () {
6460
"width" : "400"
6561
}]
6662
})
67-
expect(url).to.match(/^https\:\/\/ik\.imagekit\.io\/test\_url\_endpoint\/[^\/]/);
68-
expect(url).to.match(new RegExp("[^\/]\/tr:"));
69-
expect(url).to.match(new RegExp(":h-300,w-400"));
70-
expect(url).to.match(/[^\/]\/test_path\.jpg[^\/][\?]?/);
71-
expect(url).to.match(/ik\-sdk\-version\=javascript\-\d\.\d\.\d/);
63+
64+
expect(url).equal(`https://ik.imagekit.io/test_url_endpoint/tr:h-300,w-400/test_path.jpg?ik-sdk-version=javascript-${pkg.version}`);
7265

7366
});
7467

@@ -81,11 +74,8 @@ describe("Testing SDK", function () {
8174
"width" : "400"
8275
}]
8376
})
84-
expect(url).to.match(/^https\:\/\/ik\.imagekit\.io\/test\_url\_endpoint\_alt\/[^\/]/);
85-
expect(url).to.match(new RegExp("[^\/]\/tr:"));
86-
expect(url).to.match(new RegExp(":h-300,w-400"));
87-
expect(url).to.match(/[^\/]\/test_path\.jpg[^\/][\?]?/);
88-
expect(url).to.match(/ik\-sdk\-version\=javascript\-\d\.\d\.\d/);
77+
78+
expect(url).equal(`https://ik.imagekit.io/test_url_endpoint_alt/tr:h-300,w-400/test_path.jpg?ik-sdk-version=javascript-${pkg.version}`);
8979

9080
});
9181

@@ -98,9 +88,8 @@ describe("Testing SDK", function () {
9888
"width" : "400"
9989
}]
10090
});
101-
expect(url).to.match(/^https\:\/\/ik\.imagekit\.io\/test\_url\_endpoint\/test\_path\.jpg\?/);
102-
expect(url).to.match(new RegExp('&tr=h-300%2Cw-400'));
103-
expect(url).to.match(/ik\-sdk\-version\=javascript\-\d\.\d\.\d/);
91+
92+
expect(url).equal(`https://ik.imagekit.io/test_url_endpoint/test_path.jpg?ik-sdk-version=javascript-${pkg.version}&tr=h-300%2Cw-400`);
10493
});
10594

10695
it('should generate the correct url with src param', function() {
@@ -111,9 +100,8 @@ describe("Testing SDK", function () {
111100
"width" : "400"
112101
}]
113102
});
114-
expect(url).to.match(/^https\:\/\/ik\.imagekit\.io\/test\_url\_endpoint\/test\_path\_alt\.jpg[^\/]/);
115-
expect(url).to.match(new RegExp('&tr=h-300%2Cw-400'));
116-
expect(url).to.match(/ik\-sdk\-version\=javascript\-\d\.\d\.\d/);
103+
104+
expect(url).equal(`https://ik.imagekit.io/test_url_endpoint/test_path_alt.jpg?ik-sdk-version=javascript-${pkg.version}&tr=h-300%2Cw-400`);
117105
});
118106

119107
it('should generate the correct url with transformationPostion as query', function() {
@@ -125,9 +113,8 @@ describe("Testing SDK", function () {
125113
"width" : "400"
126114
}]
127115
});
128-
expect(url).to.match(/^https\:\/\/ik\.imagekit\.io\/test\_url\_endpoint\/test\_path\_alt\.jpg\?/);
129-
expect(url).to.match(new RegExp('&tr=h-300%2Cw-400'));
130-
expect(url).to.match(/ik\-sdk\-version\=javascript\-\d\.\d\.\d/);
116+
117+
expect(url).equal(`https://ik.imagekit.io/test_url_endpoint/test_path_alt.jpg?ik-sdk-version=javascript-${pkg.version}&tr=h-300%2Cw-400`);
131118
});
132119

133120
it('should generate the correct url with query params properly merged', function() {
@@ -140,11 +127,7 @@ describe("Testing SDK", function () {
140127
}]
141128
});
142129

143-
expect(url).to.match(/^https\:\/\/ik\.imagekit\.io\/test\_url\_endpoint\/test\_path\_alt\.jpg\?t1=v1\&/);
144-
expect(url).to.match(new RegExp('&t2=v2&'));
145-
expect(url).to.match(new RegExp('&t3=v3&'));
146-
expect(url).to.match(new RegExp('&tr=h-300%2Cw-400'));
147-
expect(url).to.match(/ik\-sdk\-version\=javascript\-\d\.\d\.\d/);
130+
expect(url).equal(`https://ik.imagekit.io/test_url_endpoint/test_path_alt.jpg?t1=v1&ik-sdk-version=javascript-${pkg.version}&t2=v2&t3=v3&tr=h-300%2Cw-400`);
148131
});
149132

150133

@@ -159,12 +142,7 @@ describe("Testing SDK", function () {
159142
}]
160143
})
161144

162-
expect(url).to.match(/^https\:\/\/ik\.imagekit\.io\/test\_url\_endpoint\/[^\/]/);
163-
expect(url).to.match(new RegExp("[^\/]\/tr:"));
164-
expect(url).to.match(new RegExp(":h-300,w-400:rt-90"));
165-
expect(url).to.not.match(new RegExp(":rt-90:h-300,w-400"));
166-
expect(url).to.match(/[^\/]\/test_path\.jpg[^\/][\?]?/);
167-
expect(url).to.match(/ik\-sdk\-version\=javascript\-\d\.\d\.\d/);
145+
expect(url).equal(`https://ik.imagekit.io/test_url_endpoint/tr:h-300,w-400:rt-90/test_path.jpg?ik-sdk-version=javascript-${pkg.version}`);
168146
});
169147

170148

@@ -179,12 +157,7 @@ describe("Testing SDK", function () {
179157
}]
180158
})
181159

182-
expect(url).to.match(/^https\:\/\/ik\.imagekit\.io\/test\_url\_endpoint\/[^\/]/);
183-
expect(url).to.match(new RegExp("[^\/]\/tr:"));
184-
expect(url).to.match(new RegExp(":h-300,w-400:rndm_trnsf-abcd"));
185-
expect(url).to.not.match(new RegExp(":rndm_trnsf-abcd:h-300,w-400"));
186-
expect(url).to.match(/[^\/]\/test_path\.jpg[^\/][\?]?/);
187-
expect(url).to.match(/ik\-sdk\-version\=javascript\-\d\.\d\.\d/);
160+
expect(url).equal(`https://ik.imagekit.io/test_url_endpoint/tr:h-300,w-400:rndm_trnsf-abcd/test_path.jpg?ik-sdk-version=javascript-${pkg.version}`);
188161
});
189162

190163
});

yarn.lock

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -864,6 +864,13 @@
864864
magic-string "^0.25.2"
865865
resolve "^1.11.0"
866866

867+
"@rollup/plugin-json@^4.1.0":
868+
version "4.1.0"
869+
resolved "https://registry.yarnpkg.com/@rollup/plugin-json/-/plugin-json-4.1.0.tgz#54e09867ae6963c593844d8bd7a9c718294496f3"
870+
integrity sha512-yfLbTdNS6amI/2OpmbiBoW12vngr5NW2jCJVZSBEz+H5KfUJZ2M7sDjk0U6GOOdCWFVScShte29o9NezJ53TPw==
871+
dependencies:
872+
"@rollup/pluginutils" "^3.0.8"
873+
867874
"@rollup/plugin-node-resolve@^8.4.0":
868875
version "8.4.0"
869876
resolved "https://registry.yarnpkg.com/@rollup/plugin-node-resolve/-/plugin-node-resolve-8.4.0.tgz#261d79a680e9dc3d86761c14462f24126ba83575"

0 commit comments

Comments
 (0)