Skip to content

Commit 41a7c88

Browse files
Improve test coverage
1 parent 2bc9486 commit 41a7c88

File tree

8 files changed

+55
-7
lines changed

8 files changed

+55
-7
lines changed

__TESTS__/unit/transformation/transformation.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,10 @@ describe('Tests for ImageTransformation', () => {
1414
tx.addTransformation('w_100/w_200/w_300');
1515
expect(tx.toString()).toContain('w_100/w_200/w_300');
1616
});
17+
18+
it('Throws when passing a slash to an action', () => {
19+
expect(() => {
20+
tx.addAction('w_100/w_200/w_300');
21+
}).toThrow();
22+
});
1723
});
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/**
2+
* @jest-environment jsdom
3+
*/
4+
import {base64Encode} from "../../../src/internal/utils/base64Encode";
5+
6+
7+
describe('base64 test encoding', () => {
8+
it('Encodes foo', () => {
9+
expect(base64Encode('foo')).toBe('Zm9v');
10+
});
11+
12+
it('Encodes ABlasjglkaskfjgkj', () => {
13+
expect(base64Encode('ABlasjglkaskfjgkj')).toBe('QUJsYXNqZ2xrYXNrZmpna2o');
14+
});
15+
16+
17+
it('Encodes https://www.example.com', () => {
18+
expect(base64Encode('https://www.example.com')).toBe('aHR0cHM6Ly93d3cuZXhhbXBsZS5jb20');
19+
});
20+
});
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* @jest-environment node
3+
*/
4+
import {base64Encode} from "../../../src/internal/utils/base64Encode";
5+
6+
describe('base64 test encoding', () => {
7+
it('Encodes foo', () => {
8+
expect(base64Encode('foo')).toBe('Zm9v');
9+
});
10+
11+
it('Encodes ABlasjglkaskfjgkj', () => {
12+
expect(base64Encode('ABlasjglkaskfjgkj')).toBe('QUJsYXNqZ2xrYXNrZmpna2o');
13+
});
14+
15+
16+
it('Encodes https://www.example.com', () => {
17+
expect(base64Encode('https://www.example.com')).toBe('aHR0cHM6Ly93d3cuZXhhbXBsZS5jb20');
18+
});
19+
});

jest.config.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"preset": "ts-jest",
3-
"testEnvironment": "node",
3+
"testEnvironment": "jsdom",
44
"bail": true,
55
"collectCoverageFrom": [
66
"<rootDir>/src/**/*.ts",

scripts/errors/FoundNonRequiredFile.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
class FoundNonRequiredFile extends Error {
22
constructor(filePath:string) {
3-
// Required due to https://github.com/microsoft/TypeScript/issues/13029
4-
super(); /* istanbul ignore next */
3+
super();
54
this.message = `File not required by Tree but exists in file system: ${filePath}`;
65
this.name = "FoundNonRequiredFile";
76
}

scripts/errors/MissingRequiredFile.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
class MissingRequiredFile extends Error {
22
constructor(currentPath:string) {
3-
// Required due to https://github.com/microsoft/TypeScript/issues/13029
4-
super(); /* istanbul ignore next */
3+
super();
54
this.message = `File ${currentPath} does not exist, \nIf you added a new file or folder, please update the validation step`;
65
this.name = "MissingRequiredFileError";
76
}

src/internal/utils/base64Encode.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,16 @@
66
*/
77
function base64Encode(input: string):string {
88
// Browser
9+
let encodedResult = '';
10+
911
if (typeof window !== 'undefined') {
10-
return btoa(input);
12+
encodedResult = btoa(input);
1113
} else {
1214
// NodeJS support
13-
return global.Buffer.from(input).toString('base64');
15+
encodedResult = global.Buffer.from(input).toString('base64');
1416
}
17+
18+
return encodedResult.replace(/=+$/, ''); // Remove ending '='
1519
}
1620

1721
export {base64Encode};

src/values/source/sourceTypes/TextSource.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {TextStyle} from "../../textStyle";
88
*/
99
class TextSource extends BaseTextSource {
1010
constructor(fileName: string, textStyle: TextStyle) {
11+
/* istanbul ignore next */
1112
super(fileName, textStyle);
1213
}
1314
}

0 commit comments

Comments
 (0)