Skip to content

Commit

Permalink
tests: adding unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
aorumbayev committed Dec 7, 2023
1 parent c366095 commit 4d3385f
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
"extension:package": "vsce package",
"extension:publish": "vsce publish",
"extension:publish-pre-release": "vsce publish --pre-release",
"test": "ts-mocha -p tsconfig.json tests/*test.ts --timeout 30s --diff false",
"test": "ts-mocha -p tsconfig.json 'tests/**/*test.ts' --timeout 30s --diff false",
"test:coverage": "nyc npm run test"
},
"dependencies": {
Expand Down
2 changes: 1 addition & 1 deletion src/common/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ export class ByteArrayMap<T> {
}
}

function filePathRelativeTo(base: string, filePath: string): string {
export function filePathRelativeTo(base: string, filePath: string): string {
// Normalize the base path to convert any Windows backslashes to forward slashes
// This is necessary because the URL object expects forward slashes
const normalizedBase = base.replace(/\\/g, '/');
Expand Down
31 changes: 31 additions & 0 deletions tests/common/utils.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import * as assert from 'assert';
import { filePathRelativeTo } from '../../src/common/utils';

describe('Utils Tests', () => {
describe('filePathRelativeTo', () => {
// Given a valid base path and file path, it should return the correct relative file path.
it('should return the correct relative file path when arguments are unix like', () => {
const base = '/somelongpath/sources/sources.avm.json';
const filePath = 'slot-machine/slot-machine.teal.tok.map';

const result = filePathRelativeTo(base, filePath);

assert.strictEqual(
result,
'/somelongpath/sources/slot-machine/slot-machine.teal.tok.map',
);
});

it('should return the correct relative file path when arguments is windows like', () => {
const base = '\\somelongpath\\sources\\sources.avm.json';
const filePath = 'slot-machine/slot-machine.teal.tok.map';

const result = filePathRelativeTo(base, filePath);

assert.strictEqual(
result,
'/somelongpath/sources/slot-machine/slot-machine.teal.tok.map',
);
});
});
});

0 comments on commit 4d3385f

Please sign in to comment.