Skip to content

Commit 479271a

Browse files
committed
test cases updated and some fixes
1 parent 8be4d39 commit 479271a

24 files changed

+95
-2967
lines changed

.babelrc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"presets": [
3+
"@babel/preset-env",
4+
"@babel/preset-typescript"
5+
]
6+
}

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ node_modules/*
44
coverage.lcov
55
coverage
66
.DS_Store
7-
dist/*
7+
dist

.mocharc.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"extension": ["ts"],
3+
"spec": "tests/*.js",
4+
"require": "babel-register.js"
5+
}

babel-register.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
const register = require('@babel/register').default;
2+
3+
register({ extensions: ['.ts', '.tsx', '.js', '.jsx'] });

index.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ import signature from "./libs/signature";
1414
/*
1515
Utils
1616
*/
17-
var pHashUtils = require('./utils/phash');
18-
var transformationUtils = require('./utils/transformation');
19-
var errorMessages = require("./constants/errorMessages");
17+
import pHashUtils from "./utils/phash";
18+
import transformationUtils from "./utils/transformation";
19+
import errorMessages from "./libs/constants/errorMessages";
2020

2121
import { IKCallback } from "./libs/interfaces/IKCallback";
2222
import {
@@ -276,9 +276,9 @@ var ImageKit = function(
276276
this: IImageKit,
277277
firstPHash: string,
278278
secondPHash: string
279-
) : number {
279+
) : number | Error {
280280
return pHashUtils.pHashDistance(firstPHash, secondPHash);
281281
}
282282
};
283283

284-
module.exports = ImageKit;
284+
export default ImageKit;

libs/constants/supportedTransforms.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,10 @@
121121
* @see {@link https://docs.imagekit.io/features/image-transformations/overlay#overlay-image-cropping}
122122
*/
123123
overlayImageCropping: "oic",
124-
124+
/**
125+
* @see {@link https://docs.imagekit.io/features/image-transformations/overlay#oifo}
126+
*/
127+
overlayImageFocus : "oifo",
125128
/**
126129
* @see {@link https://docs.imagekit.io/features/image-transformations/overlay#trimming-of-the-overlay-image}
127130
*/

libs/interfaces/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ export interface IImageKit {
219219
* @param firstPHash
220220
* @param secondPHash
221221
*/
222-
pHashDistance: (firstPHash: string, secondPHash: string) => number;
222+
pHashDistance: (firstPHash: string, secondPHash: string) => number | Error;
223223
}
224224

225225
type FinalUrlOptions = ImageKitOptions & UrlOptions; //actual options used to construct url

libs/url/builder.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ function constructTransformationString(transformation : Array<Transformation> |
131131
if(transformation[i][key] === "-") {
132132
parsedTransformStep.push(transformKey);
133133
} else {
134-
var value = transformation[i][key] || null;
134+
var value = String(transformation[i][key]);
135135
if(transformKey === "oi" || transformKey === "di") {
136136
value = urlFormatter.removeTrailingSlash(urlFormatter.removeLeadingSlash(value));
137137
if(value) value = value.replace(/\//g,"@@");

package.json

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@
33
"version": "3.1.2",
44
"description": "Offical NodeJS SDK for ImageKit.io integration",
55
"main": "dist/index.js",
6+
"types": "dist/index.d.ts",
67
"scripts": {
78
"lint": "./node_modules/eslint/bin/eslint.js tests/ utils/phash.js",
89
"lint:fix": "./node_modules/eslint/bin/eslint.js --fix tests/ utils/phash.js",
9-
"test": "export NODE_ENV=test; tsc; nyc ./node_modules/mocha/bin/mocha --exit -t 40000 tests/*.js;ex=$?;unset NODE_ENV; exit $ex;",
10+
"check-types": "tsc",
11+
"test": "export NODE_ENV=test; nyc ./node_modules/mocha/bin/mocha --exit -t 40000 tests/*.js;ex=$?;unset NODE_ENV; exit $ex;",
1012
"report-coverage": "nyc report --reporter=text-lcov > coverage.lcov && codecov"
1113
},
1214
"author": "ImageKit Developer <[email protected]>",
@@ -22,6 +24,12 @@
2224
"node": ">=10.0.0"
2325
},
2426
"devDependencies": {
27+
"@babel/cli": "^7.14.5",
28+
"@babel/core": "^7.14.6",
29+
"@babel/node": "^7.14.5",
30+
"@babel/preset-env": "^7.14.5",
31+
"@babel/preset-typescript": "^7.14.5",
32+
"@babel/register": "^7.14.5",
2533
"@types/lodash": "^4.14.170",
2634
"@types/node": "^15.12.2",
2735
"@types/request": "^2.48.5",

tests/cache.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
const chai = require("chai");
2-
const sinon = require("sinon");
1+
import chai from "chai";
2+
import sinon from "sinon";
33
const expect = chai.expect;
44
const initializationParams = require("./data").initializationParams
5-
const ImageKit = require("..");
6-
const nock = require("nock");
5+
6+
import ImageKit from "../index";
7+
import nock from "nock";
78
var imagekit = new ImageKit(initializationParams);
89

910
const dummyAPISuccessResponse = {

0 commit comments

Comments
 (0)