Skip to content

Commit 7038b64

Browse files
committed
Test case coverage and test cases for default image
1 parent b0be175 commit 7038b64

File tree

10 files changed

+5301
-3017
lines changed

10 files changed

+5301
-3017
lines changed

.github/workflows/nodejs.yml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,11 @@ jobs:
1919
node-version: ${{ matrix.node-version }}
2020
- name: build and test
2121
run: |
22-
npm i -g yarn
23-
yarn install
24-
yarn build
25-
yarn test
22+
npm install
23+
npm run build
24+
npm run test
2625
env:
2726
CI: true
27+
- name: Publish Code Coverage
28+
run: |
29+
npm run report-coverage

.github/workflows/npmpublish.yml

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,9 @@ jobs:
2222
node-version: ${{ matrix.node-version }}
2323
- name: build and test
2424
run: |
25-
npm i -g yarn
26-
yarn install
27-
yarn build
28-
yarn test
25+
npm install
26+
npm run build
27+
npm run test
2928
env:
3029
CI: true
3130

@@ -38,11 +37,10 @@ jobs:
3837
with:
3938
node-version: 12
4039
registry-url: https://registry.npmjs.org/
41-
- name: yarn publish
40+
- name: npm publish
4241
run: |
43-
npm i -g yarn
44-
yarn build
45-
yarn config set //registry.npmjs.org/:_authToken=$NODE_AUTH_TOKEN
42+
npm run build
43+
npm config set //registry.npmjs.org/:_authToken=$NODE_AUTH_TOKEN
4644
npm publish
4745
env:
4846
NODE_AUTH_TOKEN: ${{secrets.npm_token}}

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,7 @@ samples/sample-app/node_modules/*
33
.env
44
.vscode
55
.DS_Store
6-
dist
6+
dist
7+
.nyc_output
8+
coverage.lcov
9+
coverage

CHANGELOG.md

Lines changed: 0 additions & 14 deletions
This file was deleted.

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
![brotli size](https://img.badgesize.io/https://unpkg.com/imagekit-javascript/dist/imagekit.min.js?compression=brotli&label=brotli)
77
![Node CI](https://github.com/imagekit-developer/imagekit-javascript/workflows/Node%20CI/badge.svg)
88
[![npm version](https://img.shields.io/npm/v/imagekit-javascript)](https://www.npmjs.com/package/imagekit-javascript)
9+
[![codecov](https://codecov.io/gh/imagekit-developer/imagekit-javascript/branch/master/graph/badge.svg)](https://codecov.io/gh/imagekit-developer/imagekit-javascript)
910
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
1011
[![Twitter Follow](https://img.shields.io/twitter/follow/imagekitio?label=Follow&style=social)](https://twitter.com/ImagekitIo)
1112

package-lock.json

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

package.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "imagekit-javascript",
3-
"version": "1.3.5",
3+
"version": "1.3.6",
44
"description": "Javascript SDK for using ImageKit.io in the browser",
55
"main": "dist/imagekit.cjs.js",
66
"module": "dist/imagekit.esm.js",
@@ -19,17 +19,20 @@
1919
"@rollup/plugin-json": "^4.1.0",
2020
"@rollup/plugin-node-resolve": "^8.4.0",
2121
"chai": "^4.2.0",
22+
"codecov": "^3.8.0",
2223
"formdata-node": "2.1.0",
2324
"mocha": "^7.0.1",
25+
"nyc": "^15.1.0",
2426
"rollup": "^2.22.0",
2527
"rollup-plugin-terser": "^6.1.0",
2628
"sinon": "^8.1.1"
2729
},
2830
"scripts": {
2931
"dev": "rollup -c -w",
3032
"build": "rm -rf dist*;rollup -c",
31-
"test": "export NODE_ENV=test && ./node_modules/mocha/bin/mocha --exit -t 40000 test/*.js;ex=$? ; unset NODE_ENV ; exit $ex;",
32-
"startSampleApp": "yarn build && cd samples/sample-app/ && yarn install && node index.js"
33+
"test": "export NODE_ENV=test && nyc ./node_modules/mocha/bin/mocha --exit -t 40000 test/*.js;ex=$? ; unset NODE_ENV ; exit $ex;",
34+
"startSampleApp": "yarn build && cd samples/sample-app/ && yarn install && node index.js",
35+
"report-coverage": "nyc report --reporter=text-lcov > coverage.lcov && codecov"
3336
},
3437
"repository": {
3538
"type": "git",

src/url/builder.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,8 @@ function constructTransformationString(transformation) {
116116
parsedTransformStep.push(transformKey);
117117
} else {
118118
var value = transformation[i][key];
119-
if(transformKey === "oi") {
120-
value = removeLeadingSlash(value);
119+
if(transformKey === "oi" || transformKey === "di") {
120+
value = removeTrailingSlash(removeLeadingSlash(value));
121121
value = value.replace(/\//g,"@@");
122122
}
123123
parsedTransformStep.push([transformKey, value].join(transformationUtils.getTransformKeyValueDelimiter()));

test/url-generation.js

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,68 @@ describe("URL generation", function () {
207207

208208
expect(url).equal(`https://ik.imagekit.io/test_url_endpoint/tr:h-300,w-400,b-20_FF0000/test_path.jpg?ik-sdk-version=javascript-${pkg.version}`);
209209
});
210+
211+
it('All combined', function () {
212+
const url = imagekit.url({
213+
path: "/test_path.jpg",
214+
transformation: [{
215+
height: 300,
216+
width: 400,
217+
aspectRatio: '4-3',
218+
quality: 40,
219+
crop: 'force',
220+
cropMode: 'extract',
221+
focus: 'left',
222+
format: 'jpeg',
223+
radius: 50,
224+
bg: "A94D34",
225+
border: "5-A94D34",
226+
rotation: 90,
227+
blur: 10,
228+
named: "some_name",
229+
overlayX: 35,
230+
overlayY: 35,
231+
overlayFocus: "bottom",
232+
overlayHeight: 20,
233+
overlayWidth: 20,
234+
overlayImage: "/folder/file.jpg", // leading slash case
235+
overlayImageTrim: false,
236+
overlayImageAspectRatio: "4:3",
237+
overlayImageBackground: "0F0F0F",
238+
overlayImageBorder: "10_0F0F0F",
239+
overlayImageDPR: 2,
240+
overlayImageQuality: 50,
241+
overlayImageCropping: "force",
242+
overlayText: "two words",
243+
overlayTextFontSize: 20,
244+
overlayTextFontFamily: "Open Sans",
245+
overlayTextColor: "00FFFF",
246+
overlayTextTransparency: 5,
247+
overlayTextTypography: "b",
248+
overlayBackground: "00AAFF55",
249+
overlayTextEncoded: "b3ZlcmxheSBtYWRlIGVhc3k%3D",
250+
overlayTextWidth: 50,
251+
overlayTextBackground: "00AAFF55",
252+
overlayTextPadding: 40,
253+
overlayTextInnerAlignment: "left",
254+
overlayRadius: 10,
255+
progressive: true,
256+
lossless: true,
257+
trim: 5,
258+
metadata: true,
259+
colorProfile: true,
260+
defaultImage: "folder/file.jpg/", //trailing slash case
261+
dpr: 3,
262+
effectSharpen: 10,
263+
effectUSM: "2-2-0.8-0.024",
264+
effectContrast: true,
265+
effectGray: true,
266+
original: true,
267+
}]
268+
})
269+
270+
expect(url).equal(`https://ik.imagekit.io/test_url_endpoint/tr:h-300,w-400,ar-4-3,q-40,c-force,cm-extract,fo-left,f-jpeg,r-50,bg-A94D34,b-5-A94D34,rt-90,bl-10,n-some_name,ox-35,oy-35,ofo-bottom,oh-20,ow-20,oi-folder@@file.jpg,oit-false,oiar-4:3,oibg-0F0F0F,oib-10_0F0F0F,oidpr-2,oiq-50,oic-force,ot-two%20words,ots-20,otf-Open%20Sans,otc-00FFFF,oa-5,ott-b,obg-00AAFF55,ote-b3ZlcmxheSBtYWRlIGVhc3k%3D,otw-50,otbg-00AAFF55,otp-40,otia-left,or-10,pr-true,lo-true,t-5,md-true,cp-true,di-folder@@file.jpg,dpr-3,e-sharpen-10,e-usm-2-2-0.8-0.024,e-contrast-true,e-grayscale-true,orig-true/test_path.jpg?ik-sdk-version=javascript-${pkg.version}`);
271+
});
210272
});
211273

212274

0 commit comments

Comments
 (0)