-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7c5a1ed
commit 00f7a19
Showing
5 changed files
with
103 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import * as assert from 'assert'; | ||
import * as path from 'path'; | ||
import { nodeFileAccessor } from '../../src/node'; | ||
|
||
describe('Node FileAccessor Tests', () => { | ||
describe('filePathRelativeTo', () => { | ||
function getExampleAbsolutePathFor(filename: string): string { | ||
let base: string; | ||
if (nodeFileAccessor.isWindows) { | ||
base = 'C:\\somelongpath\\sources'; | ||
} else { | ||
base = '/somelongpath/sources'; | ||
} | ||
return path.join(base, filename); | ||
} | ||
|
||
interface TestCase { | ||
description: string; | ||
base: string; | ||
filePath: string; | ||
expected: string; | ||
} | ||
|
||
const testCases: TestCase[] = [ | ||
{ | ||
description: 'should be correct when the base path is a file', | ||
base: getExampleAbsolutePathFor('sources.json'), | ||
filePath: 'slot-machine/slot-machine.teal.tok.map', | ||
expected: getExampleAbsolutePathFor( | ||
['slot-machine', 'slot-machine.teal.tok.map'].join(path.sep), | ||
), | ||
}, | ||
{ | ||
description: 'should be correct when the relative path contains ..', | ||
base: getExampleAbsolutePathFor('sources.json'), | ||
filePath: '../slot-machine/slot-machine.teal.tok.map', | ||
expected: getExampleAbsolutePathFor( | ||
['..', 'slot-machine', 'slot-machine.teal.tok.map'].join(path.sep), | ||
), | ||
}, | ||
{ | ||
description: 'should be correct when the base path is a directory', | ||
base: getExampleAbsolutePathFor('directory' + path.sep), | ||
filePath: 'slot-machine/slot-machine.teal.tok.map', | ||
expected: getExampleAbsolutePathFor( | ||
['directory', 'slot-machine', 'slot-machine.teal.tok.map'].join( | ||
path.sep, | ||
), | ||
), | ||
}, | ||
{ | ||
description: 'should be correct when the file path is absolute', | ||
base: 'i do not matter', | ||
filePath: getExampleAbsolutePathFor( | ||
'slot-machine/slot-machine.teal.tok.map', | ||
), | ||
expected: getExampleAbsolutePathFor( | ||
'slot-machine/slot-machine.teal.tok.map', | ||
), | ||
}, | ||
]; | ||
|
||
for (const testCase of testCases) { | ||
it(testCase.description, () => { | ||
const result = nodeFileAccessor.filePathRelativeTo( | ||
testCase.base, | ||
testCase.filePath, | ||
); | ||
assert.strictEqual(result, testCase.expected); | ||
}); | ||
} | ||
}); | ||
}); |