@microsoft/node-core-library
Advanced tools
Comparing version 1.5.0 to 2.0.0
@@ -5,2 +5,22 @@ { | ||
{ | ||
"version": "2.0.0", | ||
"tag": "@microsoft/node-core-library_v2.0.0", | ||
"date": "Thu, 26 Jul 2018 16:04:17 GMT", | ||
"comments": { | ||
"major": [ | ||
{ | ||
"comment": "Replace IFileModeBits with a more flexible PosixModeBits enum" | ||
}, | ||
{ | ||
"comment": "Rename FileSystem.changePermissionBits() to changePosixModeBits()" | ||
} | ||
], | ||
"minor": [ | ||
{ | ||
"comment": "Add new APIs FileSystem.getPosixModeBits() and FileSystem.formatPosixModeBits()" | ||
} | ||
] | ||
} | ||
}, | ||
{ | ||
"version": "1.5.0", | ||
@@ -7,0 +27,0 @@ "tag": "@microsoft/node-core-library_v1.5.0", |
# Change Log - @microsoft/node-core-library | ||
This log was last generated on Tue, 03 Jul 2018 21:03:31 GMT and should not be manually modified. | ||
This log was last generated on Thu, 26 Jul 2018 16:04:17 GMT and should not be manually modified. | ||
## 2.0.0 | ||
Thu, 26 Jul 2018 16:04:17 GMT | ||
### Breaking changes | ||
- Replace IFileModeBits with a more flexible PosixModeBits enum | ||
- Rename FileSystem.changePermissionBits() to changePosixModeBits() | ||
### Minor changes | ||
- Add new APIs FileSystem.getPosixModeBits() and FileSystem.formatPosixModeBits() | ||
## 1.5.0 | ||
@@ -6,0 +18,0 @@ Tue, 03 Jul 2018 21:03:31 GMT |
@@ -113,8 +113,22 @@ /** | ||
* @param path - The absolute or relative path to the object that should be updated. | ||
* @param mode - UNIX-style file mode bits (e.g. 777 or 666 etc) | ||
* @param modeBits - POSIX-style file mode bits specified using the {@link PosixModeBits} enum | ||
*/ | ||
static changePermissionBits(path: string, mode: IFileModeBits): void; | ||
static changePosixModeBits(path: string, mode: PosixModeBits): void; | ||
/** | ||
* Retrieves the permissions (i.e. file mode bits) for a filesystem object. | ||
* Behind the scenes it uses `fs.chmodSync()`. | ||
* @param path - The absolute or relative path to the object that should be updated. | ||
*/ | ||
static getPosixModeBits(path: string): PosixModeBits; | ||
/** | ||
* Returns a 10-character string representation of a PosixModeBits value similar to what | ||
* would be displayed by a command such as "ls -l" on a POSIX-like operating system. | ||
* @remarks | ||
* For example, `PosixModeBits.AllRead | PosixModeBits.AllWrite` would be formatted as "-rw-rw-rw-". | ||
* @param modeBits - POSIX-style file mode bits specified using the {@link PosixModeBits} enum | ||
*/ | ||
static formatPosixModeBits(modeBits: PosixModeBits): string; | ||
/** | ||
* Moves a file. The folder must exist, unless the `ensureFolderExists` option is provided. | ||
* Behind the scenes it uses `fsx.moveSync()` | ||
* Behind the scenes it uses `fs-extra.moveSync()` | ||
* @param sourcePath - The absolute or relative path to the source file. | ||
@@ -127,3 +141,3 @@ * @param targetPath - The absolute or relative path where the file should be moved to. | ||
* Recursively creates a folder at a given path. | ||
* Behind the scenes is uses `fsx.ensureDirSync()`. | ||
* Behind the scenes is uses `fs-extra.ensureDirSync()`. | ||
* @remarks | ||
@@ -143,3 +157,3 @@ * Throws an exception if anything in the folderPath is not a folder. | ||
* Deletes a folder, including all of its contents. | ||
* Behind the scenes is uses `fsx.removeSync()`. | ||
* Behind the scenes is uses `fs-extra.removeSync()`. | ||
* @remarks | ||
@@ -152,3 +166,3 @@ * Does not throw if the folderPath does not exist. | ||
* Deletes the content of a folder, but not the folder itself. Also ensures the folder exists. | ||
* Behind the scenes it uses `fsx.emptyDirSync()`. | ||
* Behind the scenes it uses `fs-extra.emptyDirSync()`. | ||
* @remarks | ||
@@ -309,13 +323,2 @@ * This is a workaround for a common race condition, where the virus scanner holds a lock on the folder | ||
/** | ||
* Interface representing Unix-style file permission mode bits. | ||
* All values should be set. | ||
* @public | ||
*/ | ||
export declare interface IFileModeBits { | ||
Owner: PermissionsBits; | ||
Group: PermissionsBits; | ||
Other: PermissionsBits; | ||
} | ||
/** | ||
* The options for FileSystem.move() | ||
@@ -347,4 +350,8 @@ * @public | ||
* Fails if path exists. The exclusive flag ensures that path is newly created. | ||
* On POSIX systems, path is considered to exist even if it is a symlink to a non-existent file. | ||
* The exclusive flag may or may not work with network file systems. | ||
* | ||
* @remarks | ||
* On POSIX-like operating systems, path is considered to exist even if it is a symlink to a | ||
* non-existent file. The exclusive flag may or may not work with network file systems. | ||
* | ||
* POSIX is a registered trademark of the Institute of Electrical and Electronic Engineers, Inc. | ||
*/ | ||
@@ -381,3 +388,3 @@ exclusive?: boolean; | ||
*/ | ||
unixNewlines?: boolean; | ||
newlineConversion?: NewlineKind; | ||
} | ||
@@ -662,7 +669,7 @@ | ||
/** | ||
* The UNIX epoch time or Date when this was last accessed. | ||
* The POSIX epoch time or Date when this was last accessed. | ||
*/ | ||
accessedTime: number | Date; | ||
/** | ||
* The UNIX epoch time or Date when this was last modified | ||
* The POSIX epoch time or Date when this was last modified | ||
*/ | ||
@@ -892,3 +899,6 @@ modifiedTime: number | Date; | ||
/** | ||
* Unix-style newlines | ||
* POSIX-style newlines | ||
* | ||
* @remarks | ||
* POSIX is a registered trademark of the Institute of Electrical and Electronic Engineers, Inc. | ||
*/ | ||
@@ -1038,14 +1048,72 @@ Lf = "\n", | ||
/** | ||
* Available PermissionsBits bits. These can be added together using the pipe operator, e.g.: | ||
* An integer value used to specify file permissions for POSIX-like operating systems. | ||
* | ||
* PermissionsBits.Read === 1 (or "001" in decimal) | ||
* PermissionsBits.Read | PermissionsBits.Write === 3 (or "011" in decimal) | ||
* PermissionsBits.Read | PermissionsBits.Write | PermissionsBits.Execute === 7 (or "111" in decimal) | ||
* @remarks | ||
* | ||
* This bitfield corresponds to the "mode_t" structure described in this document: | ||
* http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/sys_stat.h.html | ||
* | ||
* It is used with NodeJS APIs such as fs.Stat.mode and fs.chmodSync(). These values | ||
* represent a set of permissions and can be combined using bitwise arithmetic. | ||
* | ||
* POSIX is a registered trademark of the Institute of Electrical and Electronic Engineers, Inc. | ||
* | ||
* @public | ||
*/ | ||
declare const enum PermissionsBits { | ||
export declare const enum PosixModeBits { | ||
/** | ||
* Indicates that the item's owner can read the item. | ||
*/ | ||
UserRead = 256, | ||
/** | ||
* Indicates that the item's owner can modify the item. | ||
*/ | ||
UserWrite = 128, | ||
/** | ||
* Indicates that the item's owner can execute the item (if it is a file) | ||
* or search the item (if it is a directory). | ||
*/ | ||
UserExecute = 64, | ||
/** | ||
* Indicates that users belonging to the item's group can read the item. | ||
*/ | ||
GroupRead = 32, | ||
/** | ||
* Indicates that users belonging to the item's group can modify the item. | ||
*/ | ||
GroupWrite = 16, | ||
/** | ||
* Indicates that users belonging to the item's group can execute the item (if it is a file) | ||
* or search the item (if it is a directory). | ||
*/ | ||
GroupExecute = 8, | ||
/** | ||
* Indicates that other users (besides the item's owner user or group) can read the item. | ||
*/ | ||
OthersRead = 4, | ||
/** | ||
* Indicates that other users (besides the item's owner user or group) can modify the item. | ||
*/ | ||
OthersWrite = 2, | ||
/** | ||
* Indicates that other users (besides the item's owner user or group) can execute the item (if it is a file) | ||
* or search the item (if it is a directory). | ||
*/ | ||
OthersExecute = 1, | ||
/** | ||
* A zero value where no permissions bits are set. | ||
*/ | ||
None = 0, | ||
Execute = 1, | ||
Write = 2, | ||
Read = 4, | ||
/** | ||
* An alias combining OthersRead, GroupRead, and UserRead permission bits. | ||
*/ | ||
AllRead = 292, | ||
/** | ||
* An alias combining OthersWrite, GroupWrite, and UserWrite permission bits. | ||
*/ | ||
AllWrite = 146, | ||
/** | ||
* An alias combining OthersExecute, GroupExecute, and UserExecute permission bits. | ||
*/ | ||
AllExecute = 73, | ||
} | ||
@@ -1137,3 +1205,5 @@ | ||
/** | ||
* Converts all newlines in the provided string to use Unix-style LF end of line characters. | ||
* Converts all newlines in the provided string to use POSIX-style LF end of line characters. | ||
* | ||
* POSIX is a registered trademark of the Institute of Electrical and Electronic Engineers, Inc. | ||
*/ | ||
@@ -1140,0 +1210,0 @@ static convertToLf(input: string): string; |
@@ -68,7 +68,3 @@ "use strict"; | ||
// Set to read-only so that developer doesn't accidentally modify the wrong file | ||
FileSystem_1.FileSystem.changePermissionBits(expectedCopyFilename, { | ||
Owner: 4 /* Read */, | ||
Group: 4 /* Read */, | ||
Other: 4 /* Read */ | ||
}); | ||
FileSystem_1.FileSystem.changePosixModeBits(expectedCopyFilename, 292 /* AllRead */); | ||
throw new Error('The test output file does not match the expected input:\n' | ||
@@ -75,0 +71,0 @@ + actualFilePath); |
@@ -20,3 +20,6 @@ /// <reference types="node" /> | ||
/** | ||
* Unix-style newlines | ||
* POSIX-style newlines | ||
* | ||
* @remarks | ||
* POSIX is a registered trademark of the Institute of Electrical and Electronic Engineers, Inc. | ||
*/ | ||
@@ -26,26 +29,74 @@ Lf = "\n", | ||
/** | ||
* Available PermissionsBits bits. These can be added together using the pipe operator, e.g.: | ||
* An integer value used to specify file permissions for POSIX-like operating systems. | ||
* | ||
* PermissionsBits.Read === 1 (or "001" in decimal) | ||
* PermissionsBits.Read | PermissionsBits.Write === 3 (or "011" in decimal) | ||
* PermissionsBits.Read | PermissionsBits.Write | PermissionsBits.Execute === 7 (or "111" in decimal) | ||
* @remarks | ||
* | ||
* This bitfield corresponds to the "mode_t" structure described in this document: | ||
* http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/sys_stat.h.html | ||
* | ||
* It is used with NodeJS APIs such as fs.Stat.mode and fs.chmodSync(). These values | ||
* represent a set of permissions and can be combined using bitwise arithmetic. | ||
* | ||
* POSIX is a registered trademark of the Institute of Electrical and Electronic Engineers, Inc. | ||
* | ||
* @public | ||
*/ | ||
export declare const enum PermissionsBits { | ||
export declare const enum PosixModeBits { | ||
/** | ||
* Indicates that the item's owner can read the item. | ||
*/ | ||
UserRead = 256, | ||
/** | ||
* Indicates that the item's owner can modify the item. | ||
*/ | ||
UserWrite = 128, | ||
/** | ||
* Indicates that the item's owner can execute the item (if it is a file) | ||
* or search the item (if it is a directory). | ||
*/ | ||
UserExecute = 64, | ||
/** | ||
* Indicates that users belonging to the item's group can read the item. | ||
*/ | ||
GroupRead = 32, | ||
/** | ||
* Indicates that users belonging to the item's group can modify the item. | ||
*/ | ||
GroupWrite = 16, | ||
/** | ||
* Indicates that users belonging to the item's group can execute the item (if it is a file) | ||
* or search the item (if it is a directory). | ||
*/ | ||
GroupExecute = 8, | ||
/** | ||
* Indicates that other users (besides the item's owner user or group) can read the item. | ||
*/ | ||
OthersRead = 4, | ||
/** | ||
* Indicates that other users (besides the item's owner user or group) can modify the item. | ||
*/ | ||
OthersWrite = 2, | ||
/** | ||
* Indicates that other users (besides the item's owner user or group) can execute the item (if it is a file) | ||
* or search the item (if it is a directory). | ||
*/ | ||
OthersExecute = 1, | ||
/** | ||
* A zero value where no permissions bits are set. | ||
*/ | ||
None = 0, | ||
Execute = 1, | ||
Write = 2, | ||
Read = 4, | ||
/** | ||
* An alias combining OthersRead, GroupRead, and UserRead permission bits. | ||
*/ | ||
AllRead = 292, | ||
/** | ||
* An alias combining OthersWrite, GroupWrite, and UserWrite permission bits. | ||
*/ | ||
AllWrite = 146, | ||
/** | ||
* An alias combining OthersExecute, GroupExecute, and UserExecute permission bits. | ||
*/ | ||
AllExecute = 73, | ||
} | ||
/** | ||
* Interface representing Unix-style file permission mode bits. | ||
* All values should be set. | ||
* @public | ||
*/ | ||
export interface IFileModeBits { | ||
Owner: PermissionsBits; | ||
Group: PermissionsBits; | ||
Other: PermissionsBits; | ||
} | ||
/** | ||
* The options for FileSystem.readFolder() | ||
@@ -131,7 +182,7 @@ * @public | ||
/** | ||
* The UNIX epoch time or Date when this was last accessed. | ||
* The POSIX epoch time or Date when this was last accessed. | ||
*/ | ||
accessedTime: number | Date; | ||
/** | ||
* The UNIX epoch time or Date when this was last modified | ||
* The POSIX epoch time or Date when this was last modified | ||
*/ | ||
@@ -188,8 +239,22 @@ modifiedTime: number | Date; | ||
* @param path - The absolute or relative path to the object that should be updated. | ||
* @param mode - UNIX-style file mode bits (e.g. 777 or 666 etc) | ||
* @param modeBits - POSIX-style file mode bits specified using the {@link PosixModeBits} enum | ||
*/ | ||
static changePermissionBits(path: string, mode: IFileModeBits): void; | ||
static changePosixModeBits(path: string, mode: PosixModeBits): void; | ||
/** | ||
* Retrieves the permissions (i.e. file mode bits) for a filesystem object. | ||
* Behind the scenes it uses `fs.chmodSync()`. | ||
* @param path - The absolute or relative path to the object that should be updated. | ||
*/ | ||
static getPosixModeBits(path: string): PosixModeBits; | ||
/** | ||
* Returns a 10-character string representation of a PosixModeBits value similar to what | ||
* would be displayed by a command such as "ls -l" on a POSIX-like operating system. | ||
* @remarks | ||
* For example, `PosixModeBits.AllRead | PosixModeBits.AllWrite` would be formatted as "-rw-rw-rw-". | ||
* @param modeBits - POSIX-style file mode bits specified using the {@link PosixModeBits} enum | ||
*/ | ||
static formatPosixModeBits(modeBits: PosixModeBits): string; | ||
/** | ||
* Moves a file. The folder must exist, unless the `ensureFolderExists` option is provided. | ||
* Behind the scenes it uses `fsx.moveSync()` | ||
* Behind the scenes it uses `fs-extra.moveSync()` | ||
* @param sourcePath - The absolute or relative path to the source file. | ||
@@ -202,3 +267,3 @@ * @param targetPath - The absolute or relative path where the file should be moved to. | ||
* Recursively creates a folder at a given path. | ||
* Behind the scenes is uses `fsx.ensureDirSync()`. | ||
* Behind the scenes is uses `fs-extra.ensureDirSync()`. | ||
* @remarks | ||
@@ -218,3 +283,3 @@ * Throws an exception if anything in the folderPath is not a folder. | ||
* Deletes a folder, including all of its contents. | ||
* Behind the scenes is uses `fsx.removeSync()`. | ||
* Behind the scenes is uses `fs-extra.removeSync()`. | ||
* @remarks | ||
@@ -227,3 +292,3 @@ * Does not throw if the folderPath does not exist. | ||
* Deletes the content of a folder, but not the folder itself. Also ensures the folder exists. | ||
* Behind the scenes it uses `fsx.emptyDirSync()`. | ||
* Behind the scenes it uses `fs-extra.emptyDirSync()`. | ||
* @remarks | ||
@@ -230,0 +295,0 @@ * This is a workaround for a common race condition, where the virus scanner holds a lock on the folder |
"use strict"; | ||
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. | ||
// See LICENSE in the project root for license information. | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const pathUtilities = require("path"); | ||
const fs = require("fs"); | ||
const fsx = require("fs-extra"); | ||
@@ -64,12 +67,38 @@ const Text_1 = require("./Text"); | ||
* @param path - The absolute or relative path to the object that should be updated. | ||
* @param mode - UNIX-style file mode bits (e.g. 777 or 666 etc) | ||
* @param modeBits - POSIX-style file mode bits specified using the {@link PosixModeBits} enum | ||
*/ | ||
static changePermissionBits(path, mode) { | ||
// tslint:disable-next-line:no-bitwise | ||
const modeAsOctal = (mode.Owner << 6) + (mode.Group << 3) + (mode.Other); | ||
fsx.chmodSync(path, modeAsOctal); | ||
static changePosixModeBits(path, mode) { | ||
fs.chmodSync(path, mode); | ||
} | ||
/** | ||
* Retrieves the permissions (i.e. file mode bits) for a filesystem object. | ||
* Behind the scenes it uses `fs.chmodSync()`. | ||
* @param path - The absolute or relative path to the object that should be updated. | ||
*/ | ||
static getPosixModeBits(path) { | ||
return FileSystem.getStatistics(path).mode; | ||
} | ||
/** | ||
* Returns a 10-character string representation of a PosixModeBits value similar to what | ||
* would be displayed by a command such as "ls -l" on a POSIX-like operating system. | ||
* @remarks | ||
* For example, `PosixModeBits.AllRead | PosixModeBits.AllWrite` would be formatted as "-rw-rw-rw-". | ||
* @param modeBits - POSIX-style file mode bits specified using the {@link PosixModeBits} enum | ||
*/ | ||
static formatPosixModeBits(modeBits) { | ||
let result = '-'; // (later we may add support for additional states such as S_IFDIR or S_ISUID) | ||
result += (modeBits & 256 /* UserRead */) ? 'r' : '-'; | ||
result += (modeBits & 128 /* UserWrite */) ? 'w' : '-'; | ||
result += (modeBits & 64 /* UserExecute */) ? 'x' : '-'; | ||
result += (modeBits & 32 /* GroupRead */) ? 'r' : '-'; | ||
result += (modeBits & 16 /* GroupWrite */) ? 'w' : '-'; | ||
result += (modeBits & 8 /* GroupExecute */) ? 'x' : '-'; | ||
result += (modeBits & 4 /* OthersRead */) ? 'r' : '-'; | ||
result += (modeBits & 2 /* OthersWrite */) ? 'w' : '-'; | ||
result += (modeBits & 1 /* OthersExecute */) ? 'x' : '-'; | ||
return result; | ||
} | ||
/** | ||
* Moves a file. The folder must exist, unless the `ensureFolderExists` option is provided. | ||
* Behind the scenes it uses `fsx.moveSync()` | ||
* Behind the scenes it uses `fs-extra.moveSync()` | ||
* @param sourcePath - The absolute or relative path to the source file. | ||
@@ -91,3 +120,3 @@ * @param targetPath - The absolute or relative path where the file should be moved to. | ||
* Recursively creates a folder at a given path. | ||
* Behind the scenes is uses `fsx.ensureDirSync()`. | ||
* Behind the scenes is uses `fs-extra.ensureDirSync()`. | ||
* @remarks | ||
@@ -119,3 +148,3 @@ * Throws an exception if anything in the folderPath is not a folder. | ||
* Deletes a folder, including all of its contents. | ||
* Behind the scenes is uses `fsx.removeSync()`. | ||
* Behind the scenes is uses `fs-extra.removeSync()`. | ||
* @remarks | ||
@@ -130,3 +159,3 @@ * Does not throw if the folderPath does not exist. | ||
* Deletes the content of a folder, but not the folder itself. Also ensures the folder exists. | ||
* Behind the scenes it uses `fsx.emptyDirSync()`. | ||
* Behind the scenes it uses `fs-extra.emptyDirSync()`. | ||
* @remarks | ||
@@ -228,3 +257,3 @@ * This is a workaround for a common race condition, where the virus scanner holds a lock on the folder | ||
static createSymbolicLinkJunction(linkTarget, linkSource) { | ||
// For directories, we use a Windows "junction". On Unix, this produces a regular symlink. | ||
// For directories, we use a Windows "junction". On POSIX operating systems, this produces a regular symlink. | ||
fsx.symlinkSync(linkTarget, linkSource, 'junction'); | ||
@@ -231,0 +260,0 @@ } |
@@ -12,4 +12,8 @@ /** | ||
* Fails if path exists. The exclusive flag ensures that path is newly created. | ||
* On POSIX systems, path is considered to exist even if it is a symlink to a non-existent file. | ||
* The exclusive flag may or may not work with network file systems. | ||
* | ||
* @remarks | ||
* On POSIX-like operating systems, path is considered to exist even if it is a symlink to a | ||
* non-existent file. The exclusive flag may or may not work with network file systems. | ||
* | ||
* POSIX is a registered trademark of the Institute of Electrical and Electronic Engineers, Inc. | ||
*/ | ||
@@ -16,0 +20,0 @@ exclusive?: boolean; |
"use strict"; | ||
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. | ||
// See LICENSE in the project root for license information. | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -3,0 +5,0 @@ const fsx = require("fs-extra"); |
@@ -18,3 +18,3 @@ /** | ||
export { Text } from './Text'; | ||
export { FileSystem, IReadFolderOptions, IWriteFileOptions, IReadFileOptions, IFileSystemMoveOptions, IDeleteFileOptions, NewlineKind, IFileModeBits, IUpdateTimeParameters } from './FileSystem'; | ||
export { FileSystem, IReadFolderOptions, IWriteFileOptions, IReadFileOptions, IFileSystemMoveOptions, IDeleteFileOptions, NewlineKind, PosixModeBits, IUpdateTimeParameters } from './FileSystem'; | ||
export { FileWriter, IFileWriterFlags } from './FileWriter'; |
import { JsonSchema, IJsonSchemaErrorInfo, IJsonSchemaValidateOptions } from './JsonSchema'; | ||
import { NewlineKind } from './FileSystem'; | ||
/** | ||
@@ -11,3 +12,3 @@ * Options for JsonFile.stringify() | ||
*/ | ||
unixNewlines?: boolean; | ||
newlineConversion?: NewlineKind; | ||
} | ||
@@ -14,0 +15,0 @@ /** |
@@ -56,8 +56,11 @@ "use strict"; | ||
const stringified = JSON.stringify(jsonObject, undefined, 2) + '\n'; | ||
if (options && options.unixNewlines) { | ||
return stringified; | ||
if (options && options.newlineConversion) { | ||
switch (options.newlineConversion) { | ||
case "\r\n" /* CrLf */: | ||
return Text_1.Text.convertToCrLf(stringified); | ||
case "\n" /* Lf */: | ||
return Text_1.Text.convertToLf(stringified); | ||
} | ||
} | ||
else { | ||
return Text_1.Text.convertToCrLf(stringified); | ||
} | ||
return stringified; | ||
} | ||
@@ -64,0 +67,0 @@ /** |
@@ -5,4 +5,2 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
/// <reference types='mocha' /> | ||
const chai_1 = require("chai"); | ||
const path = require("path"); | ||
@@ -18,9 +16,15 @@ const JsonFile_1 = require("../JsonFile"); | ||
const schema = JsonSchema_1.JsonSchema.fromFile(schemaPath); | ||
it('loadAndValidate successfully validates a JSON file', (done) => { | ||
it('loadAndValidate successfully validates a JSON file', () => { | ||
const jsonPath = path.resolve(path.join(__dirname, './test-data/test.json')); | ||
const jsonObject = JsonFile_1.JsonFile.loadAndValidate(jsonPath, schema); | ||
chai_1.assert.isObject(jsonObject); | ||
done(); | ||
expect(jsonObject).toMatchObject({ | ||
'exampleString': 'This is a string', | ||
'exampleArray': [ | ||
'apple', | ||
'banana', | ||
'coconut' | ||
] | ||
}); | ||
}); | ||
it('validateObjectWithCallback successfully reports a compound validation error', (done) => { | ||
it('validateObjectWithCallback successfully reports a compound validation error', () => { | ||
const jsonPath2 = path.resolve(path.join(__dirname, './test-data/test2.json')); | ||
@@ -38,7 +42,5 @@ const jsonObject2 = JsonFile_1.JsonFile.load(jsonPath2); | ||
++errorCount; | ||
console.log(errorInfo.details); | ||
chai_1.assert.equal(normalize(errorInfo.details), normalize(expectedError), 'Error #' + errorCount.toString()); | ||
expect(normalize(errorInfo.details)).toEqual(normalize(expectedError)); | ||
}); | ||
chai_1.assert.equal(errorCount, 1); | ||
done(); | ||
expect(errorCount).toEqual(1); | ||
}); | ||
@@ -45,0 +47,0 @@ }); |
@@ -5,4 +5,2 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
/// <reference types='mocha' /> | ||
const chai_1 = require("chai"); | ||
const path = require("path"); | ||
@@ -22,29 +20,29 @@ const LockFile_1 = require("../LockFile"); | ||
it('only acceps alphabetical characters for resource name', () => { | ||
chai_1.assert.doesNotThrow(() => { | ||
expect(() => { | ||
LockFile_1.LockFile.getLockFilePath(process.cwd(), 'foo123'); | ||
}); | ||
chai_1.assert.doesNotThrow(() => { | ||
}).not.toThrow(); | ||
expect(() => { | ||
LockFile_1.LockFile.getLockFilePath(process.cwd(), 'bar.123'); | ||
}); | ||
chai_1.assert.doesNotThrow(() => { | ||
}).not.toThrow(); | ||
expect(() => { | ||
LockFile_1.LockFile.getLockFilePath(process.cwd(), 'foo.bar'); | ||
}); | ||
chai_1.assert.doesNotThrow(() => { | ||
}).not.toThrow(); | ||
expect(() => { | ||
LockFile_1.LockFile.getLockFilePath(process.cwd(), 'lock-file.123'); | ||
}); | ||
chai_1.assert.throws(() => { | ||
}).not.toThrow(); | ||
expect(() => { | ||
LockFile_1.LockFile.getLockFilePath(process.cwd(), '.foo123'); | ||
}); | ||
chai_1.assert.throws(() => { | ||
}).toThrow(); | ||
expect(() => { | ||
LockFile_1.LockFile.getLockFilePath(process.cwd(), 'foo123.'); | ||
}); | ||
chai_1.assert.throws(() => { | ||
}).toThrow(); | ||
expect(() => { | ||
LockFile_1.LockFile.getLockFilePath(process.cwd(), '-foo123'); | ||
}); | ||
chai_1.assert.throws(() => { | ||
}).toThrow(); | ||
expect(() => { | ||
LockFile_1.LockFile.getLockFilePath(process.cwd(), 'foo123-'); | ||
}); | ||
chai_1.assert.throws(() => { | ||
}).toThrow(); | ||
expect(() => { | ||
LockFile_1.LockFile.getLockFilePath(process.cwd(), ''); | ||
}); | ||
}).toThrow(); | ||
}); | ||
@@ -63,3 +61,3 @@ }); | ||
const ret = LockFile_1.getProcessStartTimeFromProcStat(stat); | ||
chai_1.assert.strictEqual(ret, undefined); | ||
expect(ret).toBeUndefined(); | ||
}); | ||
@@ -69,3 +67,3 @@ it('returns undefined if too few values are contained in /proc/[pid]/stat (2)', () => { | ||
const ret = LockFile_1.getProcessStartTimeFromProcStat(stat); | ||
chai_1.assert.strictEqual(ret, undefined); | ||
expect(ret).toBeUndefined(); | ||
}); | ||
@@ -77,3 +75,3 @@ it('returns the correct start time if the second value in /proc/[pid]/stat contains spaces', () => { | ||
const ret = LockFile_1.getProcessStartTimeFromProcStat(stat); | ||
chai_1.assert.strictEqual(ret, value22); | ||
expect(ret).toEqual(value22); | ||
}); | ||
@@ -86,3 +84,3 @@ it('returns the correct start time if there are 22 values in /proc/[pid]/stat, including a trailing line ' | ||
const ret = LockFile_1.getProcessStartTimeFromProcStat(stat); | ||
chai_1.assert.strictEqual(ret, value22); | ||
expect(ret).toEqual(value22); | ||
}); | ||
@@ -94,3 +92,3 @@ it('returns the correct start time if the second value in /proc/[pid]/stat does not contain spaces', () => { | ||
const ret = LockFile_1.getProcessStartTimeFromProcStat(stat); | ||
chai_1.assert.strictEqual(ret, value22); | ||
expect(ret).toEqual(value22); | ||
}); | ||
@@ -102,6 +100,6 @@ }); | ||
it('returns a resolved path containing the pid', () => { | ||
chai_1.assert.equal(path.join(process.cwd(), `test#${process.pid}.lock`), LockFile_1.LockFile.getLockFilePath('./', 'test')); | ||
expect(path.join(process.cwd(), `test#${process.pid}.lock`)).toEqual(LockFile_1.LockFile.getLockFilePath('./', 'test')); | ||
}); | ||
it('allows for overridden pid', () => { | ||
chai_1.assert.equal(path.join(process.cwd(), `test#99.lock`), LockFile_1.LockFile.getLockFilePath('./', 'test', 99)); | ||
expect(path.join(process.cwd(), `test#99.lock`)).toEqual(LockFile_1.LockFile.getLockFilePath('./', 'test', 99)); | ||
}); | ||
@@ -117,14 +115,14 @@ }); | ||
// The lockfile should exist and be in a clean state | ||
chai_1.assert.isDefined(lock); | ||
chai_1.assert.isFalse(lock.dirtyWhenAcquired); | ||
chai_1.assert.isFalse(lock.isReleased); | ||
chai_1.assert.isTrue(FileSystem_1.FileSystem.exists(pidLockFileName)); | ||
expect(lock).toBeDefined(); | ||
expect(lock.dirtyWhenAcquired).toEqual(false); | ||
expect(lock.isReleased).toEqual(false); | ||
expect(FileSystem_1.FileSystem.exists(pidLockFileName)).toEqual(true); | ||
// Ensure that we can release the "clean" lockfile | ||
lock.release(); | ||
chai_1.assert.isFalse(FileSystem_1.FileSystem.exists(pidLockFileName)); | ||
chai_1.assert.isTrue(lock.isReleased); | ||
expect(FileSystem_1.FileSystem.exists(pidLockFileName)).toEqual(false); | ||
expect(lock.isReleased).toEqual(true); | ||
// Ensure we cannot release the lockfile twice | ||
chai_1.assert.throws(() => { | ||
expect(() => { | ||
lock.release(); | ||
}); | ||
}).toThrow(); | ||
}); | ||
@@ -152,3 +150,3 @@ it('cannot acquire a lock if another valid lock exists', () => { | ||
// this lock should be undefined since there is an existing lock | ||
chai_1.assert.isUndefined(lock); | ||
expect(lock).toBeUndefined(); | ||
}); | ||
@@ -160,6 +158,6 @@ }); | ||
it('returns a resolved path that doesn\'t contain', () => { | ||
chai_1.assert.equal(path.join(process.cwd(), `test.lock`), LockFile_1.LockFile.getLockFilePath('./', 'test')); | ||
expect(path.join(process.cwd(), `test.lock`)).toEqual(LockFile_1.LockFile.getLockFilePath('./', 'test')); | ||
}); | ||
it('ignores pid that is passed in', () => { | ||
chai_1.assert.equal(path.join(process.cwd(), `test.lock`), LockFile_1.LockFile.getLockFilePath('./', 'test', 99)); | ||
expect(path.join(process.cwd(), `test.lock`)).toEqual(LockFile_1.LockFile.getLockFilePath('./', 'test', 99)); | ||
}); | ||
@@ -178,3 +176,3 @@ }); | ||
// this lock should be undefined since there is an existing lock | ||
chai_1.assert.isUndefined(lock); | ||
expect(lock).toBeUndefined(); | ||
lockFileHandle.close(); | ||
@@ -192,10 +190,10 @@ }); | ||
const lock = LockFile_1.LockFile.tryAcquire(testFolder, resourceName); | ||
chai_1.assert.isDefined(lock); | ||
chai_1.assert.isTrue(lock.dirtyWhenAcquired); | ||
chai_1.assert.isFalse(lock.isReleased); | ||
chai_1.assert.isTrue(FileSystem_1.FileSystem.exists(lockFileName)); | ||
expect(lock).toBeDefined(); | ||
expect(lock.dirtyWhenAcquired).toEqual(true); | ||
expect(lock.isReleased).toEqual(false); | ||
expect(FileSystem_1.FileSystem.exists(lockFileName)).toEqual(true); | ||
// Ensure that we can release the "dirty" lockfile | ||
lock.release(); | ||
chai_1.assert.isFalse(FileSystem_1.FileSystem.exists(lockFileName)); | ||
chai_1.assert.isTrue(lock.isReleased); | ||
expect(FileSystem_1.FileSystem.exists(lockFileName)).toEqual(false); | ||
expect(lock.isReleased).toEqual(true); | ||
}); | ||
@@ -211,14 +209,14 @@ it('can acquire and close a clean lockfile', () => { | ||
// The lockfile should exist and be in a clean state | ||
chai_1.assert.isDefined(lock); | ||
chai_1.assert.isFalse(lock.dirtyWhenAcquired); | ||
chai_1.assert.isFalse(lock.isReleased); | ||
chai_1.assert.isTrue(FileSystem_1.FileSystem.exists(lockFileName)); | ||
expect(lock).toBeDefined(); | ||
expect(lock.dirtyWhenAcquired).toEqual(false); | ||
expect(lock.isReleased).toEqual(false); | ||
expect(FileSystem_1.FileSystem.exists(lockFileName)).toEqual(true); | ||
// Ensure that we can release the "clean" lockfile | ||
lock.release(); | ||
chai_1.assert.isFalse(FileSystem_1.FileSystem.exists(lockFileName)); | ||
chai_1.assert.isTrue(lock.isReleased); | ||
expect(FileSystem_1.FileSystem.exists(lockFileName)).toEqual(false); | ||
expect(lock.isReleased).toEqual(true); | ||
// Ensure we cannot release the lockfile twice | ||
chai_1.assert.throws(() => { | ||
expect(() => { | ||
lock.release(); | ||
}); | ||
}).toThrow(); | ||
}); | ||
@@ -225,0 +223,0 @@ } |
@@ -5,23 +5,19 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
/// <reference types="mocha" /> | ||
/* tslint:disable:no-function-expression - Mocha uses a poorly scoped "this" pointer */ | ||
const chai_1 = require("chai"); | ||
const path = require("path"); | ||
const PackageJsonLookup_1 = require("../PackageJsonLookup"); | ||
describe('PackageJsonLookup', function () { | ||
describe('basic tests', function () { | ||
it('tryLoadPackageJsonFor() test', function () { | ||
describe('PackageJsonLookup', () => { | ||
describe('basic tests', () => { | ||
it('tryLoadPackageJsonFor() test', () => { | ||
const packageJsonLookup = new PackageJsonLookup_1.PackageJsonLookup(); | ||
const sourceFilePath = path.join(__dirname, './test-data/example-package'); | ||
const packageJson = packageJsonLookup.tryLoadPackageJsonFor(sourceFilePath); | ||
chai_1.assert.ok(packageJson); | ||
expect(packageJson).toBeDefined(); | ||
if (packageJson) { | ||
chai_1.assert.equal(packageJson.name, 'example-package'); | ||
chai_1.assert.equal(packageJson.version, '1.0.0'); | ||
expect(packageJson.name).toEqual('example-package'); | ||
expect(packageJson.version).toEqual('1.0.0'); | ||
// The "nonstandardField" should have been trimmed because loadExtraFields=false | ||
// tslint:disable-next-line:no-string-literal | ||
chai_1.assert.notOk(packageJson['nonstandardField']); | ||
expect(packageJson).not.toHaveProperty('nonstandardField'); | ||
} | ||
}); | ||
it('tryGetPackageFolderFor() test', function () { | ||
it('tryGetPackageFolderFor() test', () => { | ||
const packageJsonLookup = new PackageJsonLookup_1.PackageJsonLookup(); | ||
@@ -31,5 +27,6 @@ const sourceFilePath = path.join(__dirname, './test-data/example-package/src/ExampleFile.txt'); | ||
const foundFolder = packageJsonLookup.tryGetPackageFolderFor(sourceFilePath); | ||
chai_1.assert.isTrue(foundFolder && foundFolder.search(/[\\/]example-package$/i) >= 0, 'Unexpected result: ' + foundFolder); | ||
expect(foundFolder).toBeDefined(); | ||
expect(foundFolder.search(/[\\/]example-package$/i)).toBeGreaterThan(0); | ||
const foundFile = packageJsonLookup.tryGetPackageJsonFilePathFor(sourceFilePath); | ||
chai_1.assert.equal(foundFile, path.join(foundFolder || '', 'package.json')); | ||
expect(foundFile).toEqual(path.join(foundFolder || '', 'package.json')); | ||
}); | ||
@@ -36,0 +33,0 @@ }); |
@@ -5,15 +5,13 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
/// <reference types='mocha' /> | ||
const PackageName_1 = require("../PackageName"); | ||
const chai_1 = require("chai"); | ||
describe('PackageName', () => { | ||
describe('Test', () => { | ||
it('isValidName() positive test', () => { | ||
chai_1.assert.isTrue(PackageName_1.PackageName.isValidName('@microsoft/node-core-library')); | ||
expect(PackageName_1.PackageName.isValidName('@microsoft/node-core-library')).toEqual(true); | ||
}); | ||
it('isValidName() negative test', () => { | ||
chai_1.assert.isFalse(PackageName_1.PackageName.isValidName('@microsoft/node-core-library/path')); | ||
expect(PackageName_1.PackageName.isValidName('@microsoft/node-core-library/path')).toEqual(false); | ||
}); | ||
it('tryParse() tests', () => { | ||
chai_1.assert.deepEqual(PackageName_1.PackageName.tryParse('@microsoft/node-core-library'), { | ||
expect(PackageName_1.PackageName.tryParse('@microsoft/node-core-library')).toEqual({ | ||
scope: '@microsoft', | ||
@@ -23,3 +21,3 @@ unscopedName: 'node-core-library', | ||
}); | ||
chai_1.assert.deepEqual(PackageName_1.PackageName.tryParse(''), { | ||
expect(PackageName_1.PackageName.tryParse('')).toEqual({ | ||
scope: '', | ||
@@ -29,4 +27,4 @@ unscopedName: '', | ||
}); | ||
chai_1.assert.deepEqual(PackageName_1.PackageName.tryParse(undefined), // tslint:disable-line:no-any | ||
{ | ||
expect(PackageName_1.PackageName.tryParse(undefined) // tslint:disable-line:no-any | ||
).toEqual({ | ||
scope: '', | ||
@@ -36,3 +34,3 @@ unscopedName: '', | ||
}); | ||
chai_1.assert.deepEqual(PackageName_1.PackageName.tryParse('@microsoft'), { | ||
expect(PackageName_1.PackageName.tryParse('@microsoft')).toEqual({ | ||
scope: '@microsoft', | ||
@@ -42,3 +40,3 @@ unscopedName: '', | ||
}); | ||
chai_1.assert.deepEqual(PackageName_1.PackageName.tryParse('@/node-core-library'), { | ||
expect(PackageName_1.PackageName.tryParse('@/node-core-library')).toEqual({ | ||
scope: '@', | ||
@@ -48,3 +46,3 @@ unscopedName: 'node-core-library', | ||
}); | ||
chai_1.assert.deepEqual(PackageName_1.PackageName.tryParse('@Microsoft/node-core-library'), { | ||
expect(PackageName_1.PackageName.tryParse('@Microsoft/node-core-library')).toEqual({ | ||
scope: '@Microsoft', | ||
@@ -54,3 +52,3 @@ unscopedName: 'node-core-library', | ||
}); | ||
chai_1.assert.deepEqual(PackageName_1.PackageName.tryParse('@micro!soft/node-core-library'), { | ||
expect(PackageName_1.PackageName.tryParse('@micro!soft/node-core-library')).toEqual({ | ||
scope: '@micro!soft', | ||
@@ -60,3 +58,3 @@ unscopedName: 'node-core-library', | ||
}); | ||
chai_1.assert.deepEqual(PackageName_1.PackageName.tryParse('@microsoft/node-co~re-library'), { | ||
expect(PackageName_1.PackageName.tryParse('@microsoft/node-co~re-library')).toEqual({ | ||
scope: '@microsoft', | ||
@@ -66,3 +64,3 @@ unscopedName: 'node-co~re-library', | ||
}); | ||
chai_1.assert.deepEqual(PackageName_1.PackageName.tryParse('@microsoft/node-core-library/path'), { | ||
expect(PackageName_1.PackageName.tryParse('@microsoft/node-core-library/path')).toEqual({ | ||
scope: '@microsoft', | ||
@@ -75,12 +73,20 @@ unscopedName: 'node-core-library/path', | ||
it('parse() test', () => { | ||
chai_1.assert.throws(() => { PackageName_1.PackageName.parse('@'); }, 'The scope must be followed by a slash'); | ||
expect(() => { PackageName_1.PackageName.parse('@'); }).toThrowError('The scope must be followed by a slash'); | ||
}); | ||
it('combineParts() tests', () => { | ||
chai_1.assert.equal(PackageName_1.PackageName.combineParts('@microsoft', 'node-core-library'), '@microsoft/node-core-library'); | ||
chai_1.assert.equal(PackageName_1.PackageName.combineParts('', 'node-core-library'), 'node-core-library'); | ||
expect(PackageName_1.PackageName.combineParts('@microsoft', 'node-core-library')) | ||
.toEqual('@microsoft/node-core-library'); | ||
expect(PackageName_1.PackageName.combineParts('', 'node-core-library')) | ||
.toEqual('node-core-library'); | ||
}); | ||
it('combineParts() errors', () => { | ||
chai_1.assert.throws(() => { PackageName_1.PackageName.combineParts('', '@microsoft/node-core-library'); }, 'The unscopedName cannot start with an "@" character'); | ||
chai_1.assert.throws(() => { PackageName_1.PackageName.combineParts('@micr!osoft', 'node-core-library'); }, 'The package name "@micr!osoft/node-core-library" contains an invalid character: "!"'); | ||
chai_1.assert.throws(() => { PackageName_1.PackageName.combineParts('', ''); }, 'The package name must not be empty'); | ||
expect(() => { | ||
PackageName_1.PackageName.combineParts('', '@microsoft/node-core-library'); | ||
}).toThrowError('The unscopedName cannot start with an "@" character'); | ||
expect(() => { | ||
PackageName_1.PackageName.combineParts('@micr!osoft', 'node-core-library'); | ||
}).toThrowError('The package name "@micr!osoft/node-core-library" contains an invalid character: "!"'); | ||
expect(() => { | ||
PackageName_1.PackageName.combineParts('', ''); | ||
}).toThrowError('The package name must not be empty'); | ||
}); | ||
@@ -87,0 +93,0 @@ }); |
@@ -5,6 +5,4 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
/// <reference types='mocha' /> | ||
const os = require("os"); | ||
const Path_1 = require("../Path"); | ||
const chai_1 = require("chai"); | ||
describe('Path', () => { | ||
@@ -14,31 +12,31 @@ describe('Test', () => { | ||
it('Windows paths', () => { | ||
chai_1.assert.isTrue(Path_1.Path.isUnder('C:\\a\\b.txt', 'C:\\a'), '1'); | ||
chai_1.assert.isTrue(Path_1.Path.isUnder('C:\\a\\b.txt', 'C:\\a\\'), '2'); | ||
chai_1.assert.isTrue(Path_1.Path.isUnder('C:\\a\\b\\c.txt', 'C:\\a'), '3'); | ||
chai_1.assert.isFalse(Path_1.Path.isUnder('C:\\a\\b.txt', 'C:\\b'), '4'); | ||
chai_1.assert.isFalse(Path_1.Path.isUnder('C:\\a\\b.txt', 'C:\\b\\'), '5'); | ||
chai_1.assert.isFalse(Path_1.Path.isUnder('C:\\a\\b\\c.txt', 'C:\\b'), '6'); | ||
chai_1.assert.isFalse(Path_1.Path.isUnder('C:\\a\\b.txt', 'D:\\a'), '7'); | ||
expect(Path_1.Path.isUnder('C:\\a\\b.txt', 'C:\\a')).toEqual(true); | ||
expect(Path_1.Path.isUnder('C:\\a\\b.txt', 'C:\\a\\')).toEqual(true); | ||
expect(Path_1.Path.isUnder('C:\\a\\b\\c.txt', 'C:\\a')).toEqual(true); | ||
expect(Path_1.Path.isUnder('C:\\a\\b.txt', 'C:\\b')).toEqual(false); | ||
expect(Path_1.Path.isUnder('C:\\a\\b.txt', 'C:\\b\\')).toEqual(false); | ||
expect(Path_1.Path.isUnder('C:\\a\\b\\c.txt', 'C:\\b')).toEqual(false); | ||
expect(Path_1.Path.isUnder('C:\\a\\b.txt', 'D:\\a')).toEqual(false); | ||
}); | ||
} | ||
it('Unix paths', () => { | ||
chai_1.assert.isTrue(Path_1.Path.isUnder('/a/b.txt', '/a'), '1'); | ||
chai_1.assert.isTrue(Path_1.Path.isUnder('/a/b.txt', '/a/'), '2'); | ||
chai_1.assert.isTrue(Path_1.Path.isUnder('/a/b/c.txt', '/a'), '3'); | ||
chai_1.assert.isFalse(Path_1.Path.isUnder('/a/b.txt', '/b'), '4'); | ||
chai_1.assert.isFalse(Path_1.Path.isUnder('/a/b.txt', '/b/'), '5'); | ||
chai_1.assert.isFalse(Path_1.Path.isUnder('/a/b/c.txt', '/b'), '6'); | ||
it('POSIX-style paths', () => { | ||
expect(Path_1.Path.isUnder('/a/b.txt', '/a')).toEqual(true); | ||
expect(Path_1.Path.isUnder('/a/b.txt', '/a/')).toEqual(true); | ||
expect(Path_1.Path.isUnder('/a/b/c.txt', '/a')).toEqual(true); | ||
expect(Path_1.Path.isUnder('/a/b.txt', '/b')).toEqual(false); | ||
expect(Path_1.Path.isUnder('/a/b.txt', '/b/')).toEqual(false); | ||
expect(Path_1.Path.isUnder('/a/b/c.txt', '/b')).toEqual(false); | ||
}); | ||
it('Edge cases', () => { | ||
chai_1.assert.isFalse(Path_1.Path.isUnder('/a', '/a'), '1'); | ||
chai_1.assert.isFalse(Path_1.Path.isUnder('.', '.'), '2'); | ||
chai_1.assert.isFalse(Path_1.Path.isUnder('', ''), '3'); | ||
expect(Path_1.Path.isUnder('/a', '/a')).toEqual(false); | ||
expect(Path_1.Path.isUnder('.', '.')).toEqual(false); | ||
expect(Path_1.Path.isUnder('', '')).toEqual(false); | ||
}); | ||
it('Relative paths', () => { | ||
chai_1.assert.isTrue(Path_1.Path.isUnder('a/b/c', 'a/b'), '1'); | ||
chai_1.assert.isTrue(Path_1.Path.isUnder('./a/b/c', './a/b'), '2'); | ||
chai_1.assert.isTrue(Path_1.Path.isUnder('../a/b/c', '../a/b'), '3'); | ||
chai_1.assert.isFalse(Path_1.Path.isUnder('a/b', 'a/b/c'), '4'); | ||
chai_1.assert.isFalse(Path_1.Path.isUnder('./a/b', './a/b/c'), '5'); | ||
chai_1.assert.isFalse(Path_1.Path.isUnder('../a/b', '../a/b/c'), '6'); | ||
expect(Path_1.Path.isUnder('a/b/c', 'a/b')).toEqual(true); | ||
expect(Path_1.Path.isUnder('./a/b/c', './a/b')).toEqual(true); | ||
expect(Path_1.Path.isUnder('../a/b/c', '../a/b')).toEqual(true); | ||
expect(Path_1.Path.isUnder('a/b', 'a/b/c')).toEqual(false); | ||
expect(Path_1.Path.isUnder('./a/b', './a/b/c')).toEqual(false); | ||
expect(Path_1.Path.isUnder('../a/b', '../a/b/c')).toEqual(false); | ||
}); | ||
@@ -45,0 +43,0 @@ }); |
@@ -5,5 +5,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
/// <reference types='mocha' /> | ||
const ProtectableMap_1 = require("../ProtectableMap"); | ||
const chai_1 = require("chai"); | ||
class ExampleApi { | ||
@@ -50,8 +48,8 @@ constructor() { | ||
exampleApi.studentAgesByName.delete('CHARLIE'); | ||
chai_1.assert.equal(exampleApi.clearedCount, 1); | ||
chai_1.assert.equal(exampleApi.setCount, 4); | ||
chai_1.assert.equal(exampleApi.deletedCount, 1); | ||
chai_1.assert.equal(exampleApi.studentAgesByName.get('ALICE'), 23); | ||
chai_1.assert.equal(exampleApi.studentAgesByName.get('BOB'), 0); // clamped by onSet() | ||
chai_1.assert.equal(exampleApi.studentAgesByName.has('CHARLIE'), false); | ||
expect(exampleApi.clearedCount).toEqual(1); | ||
expect(exampleApi.setCount).toEqual(4); | ||
expect(exampleApi.deletedCount).toEqual(1); | ||
expect(exampleApi.studentAgesByName.get('ALICE')).toEqual(23); | ||
expect(exampleApi.studentAgesByName.get('BOB')).toEqual(0); // clamped by onSet() | ||
expect(exampleApi.studentAgesByName.has('CHARLIE')).toEqual(false); | ||
}); | ||
@@ -62,10 +60,10 @@ it('Unprotected operations', () => { | ||
// Interacting directly with the ProtectableMap bypasses the hooks | ||
chai_1.assert.equal(exampleApi.clearedCount, 0); | ||
chai_1.assert.equal(exampleApi.studentAgesByName.get('Dave'), -123); | ||
expect(exampleApi.clearedCount).toEqual(0); | ||
expect(exampleApi.studentAgesByName.get('Dave')).toEqual(-123); | ||
}); | ||
it('Error case', () => { | ||
const exampleApi = new ExampleApi(); | ||
chai_1.assert.throw(() => { | ||
expect(() => { | ||
exampleApi.studentAgesByName.set('Jane', 23); | ||
}, 'The key must be all upper case: Jane'); | ||
}).toThrowError('The key must be all upper case: Jane'); | ||
}); | ||
@@ -72,0 +70,0 @@ }); |
@@ -5,23 +5,23 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
/// <reference types='mocha' /> | ||
const Text_1 = require("../Text"); | ||
const chai_1 = require("chai"); | ||
describe('Text', () => { | ||
it('Text.padEnd()', () => { | ||
chai_1.assert.equal(Text_1.Text.padEnd('', 5), ' '); | ||
chai_1.assert.equal(Text_1.Text.padEnd('123', 5), '123 '); | ||
chai_1.assert.equal(Text_1.Text.padEnd('12345', 5), '12345'); | ||
chai_1.assert.equal(Text_1.Text.padEnd('123456', 5), '123456'); | ||
expect(Text_1.Text.padEnd('', 5)).toEqual(' '); | ||
expect(Text_1.Text.padEnd('123', 5)).toEqual('123 '); | ||
expect(Text_1.Text.padEnd('12345', 5)).toEqual('12345'); | ||
expect(Text_1.Text.padEnd('123456', 5)).toEqual('123456'); | ||
}); | ||
it('Text.truncateWithEllipsis()', () => { | ||
chai_1.assert.throws(() => { Text_1.Text.truncateWithEllipsis('123', -1); }); | ||
chai_1.assert.equal(Text_1.Text.truncateWithEllipsis('123', 0), ''); | ||
chai_1.assert.equal(Text_1.Text.truncateWithEllipsis('', 2), ''); | ||
chai_1.assert.equal(Text_1.Text.truncateWithEllipsis('1', 2), '1'); | ||
chai_1.assert.equal(Text_1.Text.truncateWithEllipsis('12', 2), '12'); | ||
chai_1.assert.equal(Text_1.Text.truncateWithEllipsis('123', 2), '12'); | ||
chai_1.assert.equal(Text_1.Text.truncateWithEllipsis('123', 5), '123'); | ||
chai_1.assert.equal(Text_1.Text.truncateWithEllipsis('1234', 5), '1234'); | ||
chai_1.assert.equal(Text_1.Text.truncateWithEllipsis('12345', 5), '12345'); | ||
chai_1.assert.equal(Text_1.Text.truncateWithEllipsis('123456', 5), '12...'); | ||
expect(() => { | ||
Text_1.Text.truncateWithEllipsis('123', -1); | ||
}).toThrow(); | ||
expect(Text_1.Text.truncateWithEllipsis('123', 0)).toEqual(''); | ||
expect(Text_1.Text.truncateWithEllipsis('', 2)).toEqual(''); | ||
expect(Text_1.Text.truncateWithEllipsis('1', 2)).toEqual('1'); | ||
expect(Text_1.Text.truncateWithEllipsis('12', 2)).toEqual('12'); | ||
expect(Text_1.Text.truncateWithEllipsis('123', 2)).toEqual('12'); | ||
expect(Text_1.Text.truncateWithEllipsis('123', 5)).toEqual('123'); | ||
expect(Text_1.Text.truncateWithEllipsis('1234', 5)).toEqual('1234'); | ||
expect(Text_1.Text.truncateWithEllipsis('12345', 5)).toEqual('12345'); | ||
expect(Text_1.Text.truncateWithEllipsis('123456', 5)).toEqual('12...'); | ||
}); | ||
@@ -28,0 +28,0 @@ }); |
@@ -25,3 +25,5 @@ /** | ||
/** | ||
* Converts all newlines in the provided string to use Unix-style LF end of line characters. | ||
* Converts all newlines in the provided string to use POSIX-style LF end of line characters. | ||
* | ||
* POSIX is a registered trademark of the Institute of Electrical and Electronic Engineers, Inc. | ||
*/ | ||
@@ -28,0 +30,0 @@ static convertToLf(input: string): string; |
@@ -32,3 +32,5 @@ "use strict"; | ||
/** | ||
* Converts all newlines in the provided string to use Unix-style LF end of line characters. | ||
* Converts all newlines in the provided string to use POSIX-style LF end of line characters. | ||
* | ||
* POSIX is a registered trademark of the Institute of Electrical and Electronic Engineers, Inc. | ||
*/ | ||
@@ -35,0 +37,0 @@ static convertToLf(input) { |
{ | ||
"name": "@microsoft/node-core-library", | ||
"version": "1.5.0", | ||
"version": "2.0.0", | ||
"description": "Core libraries that every NodeJS toolchain project should use", | ||
@@ -23,9 +23,6 @@ "main": "lib/index.js", | ||
"devDependencies": { | ||
"@types/chai": "3.4.34", | ||
"@types/mocha": "2.2.38", | ||
"chai": "~3.5.0", | ||
"@types/jest": "21.1.10", | ||
"gulp": "~3.9.1", | ||
"mocha": "~3.4.2", | ||
"@microsoft/node-library-build": "4.3.41" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
422159
3
82
5486
4