mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-23 01:25:38 -05:00
Merge VS Code 1.23.1 (#1520)
This commit is contained in:
@@ -5,30 +5,17 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
import assert = require('assert');
|
||||
import os = require('os');
|
||||
import * as assert from 'assert';
|
||||
import * as os from 'os';
|
||||
|
||||
import path = require('path');
|
||||
import fs = require('fs');
|
||||
import extfs = require('vs/base/node/extfs');
|
||||
import uuid = require('vs/base/common/uuid');
|
||||
import * as path from 'path';
|
||||
import * as fs from 'fs';
|
||||
import * as uuid from 'vs/base/common/uuid';
|
||||
import { ConfigWatcher } from 'vs/base/node/config';
|
||||
import { onError } from 'vs/base/test/common/utils';
|
||||
import { mkdirp } from 'vs/base/node/pfs';
|
||||
import { testFile } from 'vs/base/test/node/utils';
|
||||
|
||||
suite('Config', () => {
|
||||
|
||||
function testFile(callback: (error: Error, path: string, cleanUp: (callback: () => void) => void) => void): void {
|
||||
const id = uuid.generateUuid();
|
||||
const parentDir = path.join(os.tmpdir(), 'vsctests', id);
|
||||
const newDir = path.join(parentDir, 'config', id);
|
||||
const testFile = path.join(newDir, 'config.json');
|
||||
|
||||
const onMkdirp = error => callback(error, testFile, (callback) => extfs.del(parentDir, os.tmpdir(), () => { }, callback));
|
||||
|
||||
mkdirp(newDir, 493).done(() => onMkdirp(null), error => onMkdirp(error));
|
||||
}
|
||||
|
||||
test('defaults', function () {
|
||||
const id = uuid.generateUuid();
|
||||
const parentDir = path.join(os.tmpdir(), 'vsctests', id);
|
||||
@@ -52,15 +39,11 @@ suite('Config', () => {
|
||||
watcher.dispose();
|
||||
});
|
||||
|
||||
test('getConfig / getValue', function (done: () => void) {
|
||||
testFile((error, testFile, cleanUp) => {
|
||||
if (error) {
|
||||
return onError(error, done);
|
||||
}
|
||||
test('getConfig / getValue', function () {
|
||||
return testFile('config', 'config.json').then(res => {
|
||||
fs.writeFileSync(res.testFile, '// my comment\n{ "foo": "bar" }');
|
||||
|
||||
fs.writeFileSync(testFile, '// my comment\n{ "foo": "bar" }');
|
||||
|
||||
let watcher = new ConfigWatcher<{ foo: string; }>(testFile);
|
||||
let watcher = new ConfigWatcher<{ foo: string; }>(res.testFile);
|
||||
|
||||
let config = watcher.getConfig();
|
||||
assert.ok(config);
|
||||
@@ -72,19 +55,15 @@ suite('Config', () => {
|
||||
|
||||
watcher.dispose();
|
||||
|
||||
cleanUp(done);
|
||||
return res.cleanUp();
|
||||
});
|
||||
});
|
||||
|
||||
test('getConfig / getValue - broken JSON', function (done: () => void) {
|
||||
testFile((error, testFile, cleanUp) => {
|
||||
if (error) {
|
||||
return onError(error, done);
|
||||
}
|
||||
test('getConfig / getValue - broken JSON', function () {
|
||||
return testFile('config', 'config.json').then(res => {
|
||||
fs.writeFileSync(res.testFile, '// my comment\n "foo": "bar ... ');
|
||||
|
||||
fs.writeFileSync(testFile, '// my comment\n "foo": "bar ... ');
|
||||
|
||||
let watcher = new ConfigWatcher<{ foo: string; }>(testFile);
|
||||
let watcher = new ConfigWatcher<{ foo: string; }>(res.testFile);
|
||||
|
||||
let config = watcher.getConfig();
|
||||
assert.ok(config);
|
||||
@@ -94,24 +73,20 @@ suite('Config', () => {
|
||||
|
||||
watcher.dispose();
|
||||
|
||||
cleanUp(done);
|
||||
return res.cleanUp();
|
||||
});
|
||||
});
|
||||
|
||||
test('watching', function (done: () => void) {
|
||||
test('watching', function (done) {
|
||||
this.timeout(10000); // watching is timing intense
|
||||
|
||||
testFile((error, testFile, cleanUp) => {
|
||||
if (error) {
|
||||
return onError(error, done);
|
||||
}
|
||||
testFile('config', 'config.json').then(res => {
|
||||
fs.writeFileSync(res.testFile, '// my comment\n{ "foo": "bar" }');
|
||||
|
||||
fs.writeFileSync(testFile, '// my comment\n{ "foo": "bar" }');
|
||||
|
||||
let watcher = new ConfigWatcher<{ foo: string; }>(testFile);
|
||||
let watcher = new ConfigWatcher<{ foo: string; }>(res.testFile);
|
||||
watcher.getConfig(); // ensure we are in sync
|
||||
|
||||
fs.writeFileSync(testFile, '// my comment\n{ "foo": "changed" }');
|
||||
fs.writeFileSync(res.testFile, '// my comment\n{ "foo": "changed" }');
|
||||
|
||||
watcher.onDidUpdateConfiguration(event => {
|
||||
assert.ok(event);
|
||||
@@ -120,24 +95,19 @@ suite('Config', () => {
|
||||
|
||||
watcher.dispose();
|
||||
|
||||
cleanUp(done);
|
||||
res.cleanUp().then(done, done);
|
||||
});
|
||||
|
||||
});
|
||||
}, done);
|
||||
});
|
||||
|
||||
test('watching also works when file created later', function (done: () => void) {
|
||||
test('watching also works when file created later', function (done) {
|
||||
this.timeout(10000); // watching is timing intense
|
||||
|
||||
testFile((error, testFile, cleanUp) => {
|
||||
if (error) {
|
||||
return onError(error, done);
|
||||
}
|
||||
|
||||
let watcher = new ConfigWatcher<{ foo: string; }>(testFile);
|
||||
testFile('config', 'config.json').then(res => {
|
||||
let watcher = new ConfigWatcher<{ foo: string; }>(res.testFile);
|
||||
watcher.getConfig(); // ensure we are in sync
|
||||
|
||||
fs.writeFileSync(testFile, '// my comment\n{ "foo": "changed" }');
|
||||
fs.writeFileSync(res.testFile, '// my comment\n{ "foo": "changed" }');
|
||||
|
||||
watcher.onDidUpdateConfiguration(event => {
|
||||
assert.ok(event);
|
||||
@@ -146,23 +116,18 @@ suite('Config', () => {
|
||||
|
||||
watcher.dispose();
|
||||
|
||||
cleanUp(done);
|
||||
res.cleanUp().then(done, done);
|
||||
});
|
||||
|
||||
});
|
||||
}, done);
|
||||
});
|
||||
|
||||
test('watching detects the config file getting deleted', function (done: () => void) {
|
||||
test('watching detects the config file getting deleted', function (done) {
|
||||
this.timeout(10000); // watching is timing intense
|
||||
|
||||
testFile((error, testFile, cleanUp) => {
|
||||
if (error) {
|
||||
return onError(error, done);
|
||||
}
|
||||
testFile('config', 'config.json').then(res => {
|
||||
fs.writeFileSync(res.testFile, '// my comment\n{ "foo": "bar" }');
|
||||
|
||||
fs.writeFileSync(testFile, '// my comment\n{ "foo": "bar" }');
|
||||
|
||||
let watcher = new ConfigWatcher<{ foo: string; }>(testFile);
|
||||
let watcher = new ConfigWatcher<{ foo: string; }>(res.testFile);
|
||||
watcher.getConfig(); // ensure we are in sync
|
||||
|
||||
watcher.onDidUpdateConfiguration(event => {
|
||||
@@ -170,25 +135,21 @@ suite('Config', () => {
|
||||
|
||||
watcher.dispose();
|
||||
|
||||
cleanUp(done);
|
||||
res.cleanUp().then(done, done);
|
||||
});
|
||||
|
||||
fs.unlinkSync(testFile);
|
||||
});
|
||||
fs.unlinkSync(res.testFile);
|
||||
}, done);
|
||||
});
|
||||
|
||||
test('reload', function (done: () => void) {
|
||||
testFile((error, testFile, cleanUp) => {
|
||||
if (error) {
|
||||
return onError(error, done);
|
||||
}
|
||||
test('reload', function (done) {
|
||||
testFile('config', 'config.json').then(res => {
|
||||
fs.writeFileSync(res.testFile, '// my comment\n{ "foo": "bar" }');
|
||||
|
||||
fs.writeFileSync(testFile, '// my comment\n{ "foo": "bar" }');
|
||||
|
||||
let watcher = new ConfigWatcher<{ foo: string; }>(testFile, { changeBufferDelay: 100, onError: console.error });
|
||||
let watcher = new ConfigWatcher<{ foo: string; }>(res.testFile, { changeBufferDelay: 100, onError: console.error });
|
||||
watcher.getConfig(); // ensure we are in sync
|
||||
|
||||
fs.writeFileSync(testFile, '// my comment\n{ "foo": "changed" }');
|
||||
fs.writeFileSync(res.testFile, '// my comment\n{ "foo": "changed" }');
|
||||
|
||||
// still old values because change is not bubbling yet
|
||||
assert.equal(watcher.getConfig().foo, 'bar');
|
||||
@@ -202,8 +163,8 @@ suite('Config', () => {
|
||||
|
||||
watcher.dispose();
|
||||
|
||||
cleanUp(done);
|
||||
res.cleanUp().then(done, done);
|
||||
});
|
||||
});
|
||||
}, done);
|
||||
});
|
||||
});
|
||||
@@ -6,7 +6,7 @@
|
||||
'use strict';
|
||||
|
||||
import * as assert from 'assert';
|
||||
import decoder = require('vs/base/node/decoder');
|
||||
import * as decoder from 'vs/base/node/decoder';
|
||||
|
||||
suite('Decoder', () => {
|
||||
|
||||
|
||||
@@ -5,71 +5,261 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
import assert = require('assert');
|
||||
|
||||
import encoding = require('vs/base/node/encoding');
|
||||
import { encodingExists } from 'vs/base/node/encoding';
|
||||
import * as assert from 'assert';
|
||||
import * as fs from 'fs';
|
||||
import * as encoding from 'vs/base/node/encoding';
|
||||
import { readExactlyByFile } from 'vs/base/node/stream';
|
||||
import { Readable } from 'stream';
|
||||
|
||||
suite('Encoding', () => {
|
||||
test('detectBOM UTF-8', (done: (err?: any) => void) => {
|
||||
test('detectBOM UTF-8', () => {
|
||||
const file = require.toUrl('./fixtures/some_utf8.css');
|
||||
|
||||
encoding.detectEncodingByBOM(file).then((encoding: string) => {
|
||||
return encoding.detectEncodingByBOM(file).then((encoding: string) => {
|
||||
assert.equal(encoding, 'utf8');
|
||||
done();
|
||||
}, done);
|
||||
});
|
||||
});
|
||||
|
||||
test('detectBOM UTF-16 LE', (done: (err?: any) => void) => {
|
||||
test('detectBOM UTF-16 LE', () => {
|
||||
const file = require.toUrl('./fixtures/some_utf16le.css');
|
||||
|
||||
encoding.detectEncodingByBOM(file).then((encoding: string) => {
|
||||
return encoding.detectEncodingByBOM(file).then((encoding: string) => {
|
||||
assert.equal(encoding, 'utf16le');
|
||||
done();
|
||||
}, done);
|
||||
});
|
||||
});
|
||||
|
||||
test('detectBOM UTF-16 BE', (done: (err?: any) => void) => {
|
||||
test('detectBOM UTF-16 BE', () => {
|
||||
const file = require.toUrl('./fixtures/some_utf16be.css');
|
||||
|
||||
encoding.detectEncodingByBOM(file).then((encoding: string) => {
|
||||
return encoding.detectEncodingByBOM(file).then((encoding: string) => {
|
||||
assert.equal(encoding, 'utf16be');
|
||||
done();
|
||||
}, done);
|
||||
});
|
||||
});
|
||||
|
||||
test('detectBOM ANSI', function (done: (err?: any) => void) {
|
||||
test('detectBOM ANSI', function () {
|
||||
const file = require.toUrl('./fixtures/some_ansi.css');
|
||||
|
||||
encoding.detectEncodingByBOM(file).then((encoding: string) => {
|
||||
return encoding.detectEncodingByBOM(file).then((encoding: string) => {
|
||||
assert.equal(encoding, null);
|
||||
done();
|
||||
}, done);
|
||||
});
|
||||
});
|
||||
|
||||
test('detectBOM ANSI', function (done: (err?: any) => void) {
|
||||
test('detectBOM ANSI', function () {
|
||||
const file = require.toUrl('./fixtures/empty.txt');
|
||||
|
||||
encoding.detectEncodingByBOM(file).then((encoding: string) => {
|
||||
return encoding.detectEncodingByBOM(file).then((encoding: string) => {
|
||||
assert.equal(encoding, null);
|
||||
done();
|
||||
}, done);
|
||||
});
|
||||
});
|
||||
|
||||
test('resolve terminal encoding (detect)', function (done: (err?: any) => void) {
|
||||
encoding.resolveTerminalEncoding().then(encoding => {
|
||||
assert.ok(encodingExists(encoding));
|
||||
done();
|
||||
}, done);
|
||||
test('resolve terminal encoding (detect)', function () {
|
||||
return encoding.resolveTerminalEncoding().then(enc => {
|
||||
assert.ok(encoding.encodingExists(enc));
|
||||
});
|
||||
});
|
||||
|
||||
test('resolve terminal encoding (environment)', function (done: (err?: any) => void) {
|
||||
test('resolve terminal encoding (environment)', function () {
|
||||
process.env['VSCODE_CLI_ENCODING'] = 'utf16le';
|
||||
|
||||
encoding.resolveTerminalEncoding().then(encoding => {
|
||||
assert.ok(encodingExists(encoding));
|
||||
assert.equal(encoding, 'utf16le');
|
||||
done();
|
||||
}, done);
|
||||
return encoding.resolveTerminalEncoding().then(enc => {
|
||||
assert.ok(encoding.encodingExists(enc));
|
||||
assert.equal(enc, 'utf16le');
|
||||
});
|
||||
});
|
||||
|
||||
test('detectEncodingFromBuffer (JSON saved as PNG)', function () {
|
||||
const file = require.toUrl('./fixtures/some.json.png');
|
||||
|
||||
return readExactlyByFile(file, 512).then(buffer => {
|
||||
const mimes = encoding.detectEncodingFromBuffer(buffer);
|
||||
assert.equal(mimes.seemsBinary, false);
|
||||
});
|
||||
});
|
||||
|
||||
test('detectEncodingFromBuffer (PNG saved as TXT)', function () {
|
||||
const file = require.toUrl('./fixtures/some.png.txt');
|
||||
return readExactlyByFile(file, 512).then(buffer => {
|
||||
const mimes = encoding.detectEncodingFromBuffer(buffer);
|
||||
assert.equal(mimes.seemsBinary, true);
|
||||
});
|
||||
});
|
||||
|
||||
test('detectEncodingFromBuffer (XML saved as PNG)', function () {
|
||||
const file = require.toUrl('./fixtures/some.xml.png');
|
||||
return readExactlyByFile(file, 512).then(buffer => {
|
||||
const mimes = encoding.detectEncodingFromBuffer(buffer);
|
||||
assert.equal(mimes.seemsBinary, false);
|
||||
});
|
||||
});
|
||||
|
||||
test('detectEncodingFromBuffer (QWOFF saved as TXT)', function () {
|
||||
const file = require.toUrl('./fixtures/some.qwoff.txt');
|
||||
return readExactlyByFile(file, 512).then(buffer => {
|
||||
const mimes = encoding.detectEncodingFromBuffer(buffer);
|
||||
assert.equal(mimes.seemsBinary, true);
|
||||
});
|
||||
});
|
||||
|
||||
test('detectEncodingFromBuffer (CSS saved as QWOFF)', function () {
|
||||
const file = require.toUrl('./fixtures/some.css.qwoff');
|
||||
return readExactlyByFile(file, 512).then(buffer => {
|
||||
const mimes = encoding.detectEncodingFromBuffer(buffer);
|
||||
assert.equal(mimes.seemsBinary, false);
|
||||
});
|
||||
});
|
||||
|
||||
test('detectEncodingFromBuffer (PDF)', function () {
|
||||
const file = require.toUrl('./fixtures/some.pdf');
|
||||
return readExactlyByFile(file, 512).then(buffer => {
|
||||
const mimes = encoding.detectEncodingFromBuffer(buffer);
|
||||
assert.equal(mimes.seemsBinary, true);
|
||||
});
|
||||
});
|
||||
|
||||
test('detectEncodingFromBuffer (guess UTF-16 LE from content without BOM)', function () {
|
||||
const file = require.toUrl('./fixtures/utf16_le_nobom.txt');
|
||||
return readExactlyByFile(file, 512).then(buffer => {
|
||||
const mimes = encoding.detectEncodingFromBuffer(buffer);
|
||||
assert.equal(mimes.encoding, encoding.UTF16le);
|
||||
assert.equal(mimes.seemsBinary, false);
|
||||
});
|
||||
});
|
||||
|
||||
test('detectEncodingFromBuffer (guess UTF-16 BE from content without BOM)', function () {
|
||||
const file = require.toUrl('./fixtures/utf16_be_nobom.txt');
|
||||
return readExactlyByFile(file, 512).then(buffer => {
|
||||
const mimes = encoding.detectEncodingFromBuffer(buffer);
|
||||
assert.equal(mimes.encoding, encoding.UTF16be);
|
||||
assert.equal(mimes.seemsBinary, false);
|
||||
});
|
||||
});
|
||||
|
||||
test('autoGuessEncoding (ShiftJIS)', function () {
|
||||
const file = require.toUrl('./fixtures/some.shiftjis.txt');
|
||||
return readExactlyByFile(file, 512 * 8).then(buffer => {
|
||||
return encoding.detectEncodingFromBuffer(buffer, true).then(mimes => {
|
||||
assert.equal(mimes.encoding, 'shiftjis');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
test('autoGuessEncoding (CP1252)', function () {
|
||||
const file = require.toUrl('./fixtures/some.cp1252.txt');
|
||||
return readExactlyByFile(file, 512 * 8).then(buffer => {
|
||||
return encoding.detectEncodingFromBuffer(buffer, true).then(mimes => {
|
||||
assert.equal(mimes.encoding, 'windows1252');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
async function readAndDecodeFromDisk(path, _encoding) {
|
||||
return new Promise<string>((resolve, reject) => {
|
||||
fs.readFile(path, (err, data) => {
|
||||
if (err) {
|
||||
reject(err);
|
||||
} else {
|
||||
resolve(encoding.decode(data, _encoding));
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
async function readAllAsString(stream: NodeJS.ReadableStream) {
|
||||
return new Promise<string>((resolve, reject) => {
|
||||
let all = '';
|
||||
stream.on('data', chunk => {
|
||||
all += chunk;
|
||||
assert.equal(typeof chunk, 'string');
|
||||
});
|
||||
stream.on('end', () => {
|
||||
resolve(all);
|
||||
});
|
||||
stream.on('error', reject);
|
||||
});
|
||||
}
|
||||
|
||||
test('toDecodeStream - some stream', async function () {
|
||||
|
||||
let source = new Readable({
|
||||
read(size) {
|
||||
this.push(Buffer.from([65, 66, 67]));
|
||||
this.push(Buffer.from([65, 66, 67]));
|
||||
this.push(Buffer.from([65, 66, 67]));
|
||||
this.push(null);
|
||||
}
|
||||
});
|
||||
|
||||
let { detected, stream } = await encoding.toDecodeStream(source, { minBytesRequiredForDetection: 4 });
|
||||
|
||||
assert.ok(detected);
|
||||
assert.ok(stream);
|
||||
|
||||
const content = await readAllAsString(stream);
|
||||
assert.equal(content, 'ABCABCABC');
|
||||
});
|
||||
|
||||
test('toDecodeStream - some stream, expect too much data', async function () {
|
||||
|
||||
let source = new Readable({
|
||||
read(size) {
|
||||
this.push(Buffer.from([65, 66, 67]));
|
||||
this.push(Buffer.from([65, 66, 67]));
|
||||
this.push(Buffer.from([65, 66, 67]));
|
||||
this.push(null);
|
||||
}
|
||||
});
|
||||
|
||||
let { detected, stream } = await encoding.toDecodeStream(source, { minBytesRequiredForDetection: 64 });
|
||||
|
||||
assert.ok(detected);
|
||||
assert.ok(stream);
|
||||
|
||||
const content = await readAllAsString(stream);
|
||||
assert.equal(content, 'ABCABCABC');
|
||||
});
|
||||
|
||||
test('toDecodeStream - some stream, no data', async function () {
|
||||
|
||||
let source = new Readable({
|
||||
read(size) {
|
||||
this.push(null); // empty
|
||||
}
|
||||
});
|
||||
|
||||
let { detected, stream } = await encoding.toDecodeStream(source, { minBytesRequiredForDetection: 512 });
|
||||
|
||||
assert.ok(detected);
|
||||
assert.ok(stream);
|
||||
|
||||
const content = await readAllAsString(stream);
|
||||
assert.equal(content, '');
|
||||
});
|
||||
|
||||
|
||||
test('toDecodeStream - encoding, utf16be', async function () {
|
||||
|
||||
let path = require.toUrl('./fixtures/some_utf16be.css');
|
||||
let source = fs.createReadStream(path);
|
||||
|
||||
let { detected, stream } = await encoding.toDecodeStream(source, { minBytesRequiredForDetection: 64 });
|
||||
|
||||
assert.equal(detected.encoding, 'utf16be');
|
||||
assert.equal(detected.seemsBinary, false);
|
||||
|
||||
let expected = await readAndDecodeFromDisk(path, detected.encoding);
|
||||
let actual = await readAllAsString(stream);
|
||||
assert.equal(actual, expected);
|
||||
});
|
||||
|
||||
|
||||
test('toDecodeStream - empty file', async function () {
|
||||
|
||||
let path = require.toUrl('./fixtures/empty.txt');
|
||||
let source = fs.createReadStream(path);
|
||||
let { detected, stream } = await encoding.toDecodeStream(source, {});
|
||||
|
||||
let expected = await readAndDecodeFromDisk(path, detected.encoding);
|
||||
let actual = await readAllAsString(stream);
|
||||
assert.equal(actual, expected);
|
||||
});
|
||||
});
|
||||
|
||||
|
Before Width: | Height: | Size: 151 B After Width: | Height: | Size: 151 B |
BIN
src/vs/base/test/node/encoding/fixtures/utf16_be_nobom.txt
Normal file
BIN
src/vs/base/test/node/encoding/fixtures/utf16_be_nobom.txt
Normal file
Binary file not shown.
BIN
src/vs/base/test/node/encoding/fixtures/utf16_le_nobom.txt
Normal file
BIN
src/vs/base/test/node/encoding/fixtures/utf16_le_nobom.txt
Normal file
Binary file not shown.
@@ -5,16 +5,15 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
import assert = require('assert');
|
||||
import os = require('os');
|
||||
import * as assert from 'assert';
|
||||
import * as os from 'os';
|
||||
|
||||
import path = require('path');
|
||||
import fs = require('fs');
|
||||
import * as path from 'path';
|
||||
import * as fs from 'fs';
|
||||
|
||||
import uuid = require('vs/base/common/uuid');
|
||||
import strings = require('vs/base/common/strings');
|
||||
import extfs = require('vs/base/node/extfs');
|
||||
import { onError } from 'vs/base/test/common/utils';
|
||||
import * as uuid from 'vs/base/common/uuid';
|
||||
import * as strings from 'vs/base/common/strings';
|
||||
import * as extfs from 'vs/base/node/extfs';
|
||||
import { Readable } from 'stream';
|
||||
import { isLinux, isWindows } from 'vs/base/common/platform';
|
||||
|
||||
@@ -58,14 +57,14 @@ function toReadable(value: string, throwError?: boolean): Readable {
|
||||
|
||||
suite('Extfs', () => {
|
||||
|
||||
test('mkdirp', function (done: () => void) {
|
||||
test('mkdirp', function (done) {
|
||||
const id = uuid.generateUuid();
|
||||
const parentDir = path.join(os.tmpdir(), 'vsctests', id);
|
||||
const newDir = path.join(parentDir, 'extfs', id);
|
||||
|
||||
mkdirp(newDir, 493, error => {
|
||||
if (error) {
|
||||
return onError(error, done);
|
||||
return done(error);
|
||||
}
|
||||
|
||||
assert.ok(fs.existsSync(newDir));
|
||||
@@ -74,7 +73,7 @@ suite('Extfs', () => {
|
||||
}); // 493 = 0755
|
||||
});
|
||||
|
||||
test('stat link', function (done: () => void) {
|
||||
test('stat link', function (done) {
|
||||
if (isWindows) {
|
||||
// Symlinks are not the same on win, and we can not create them programitically without admin privileges
|
||||
return done();
|
||||
@@ -89,21 +88,21 @@ suite('Extfs', () => {
|
||||
|
||||
mkdirp(directory, 493, error => {
|
||||
if (error) {
|
||||
return onError(error, done);
|
||||
return done(error);
|
||||
}
|
||||
|
||||
fs.symlinkSync(directory, symbolicLink);
|
||||
|
||||
extfs.statLink(directory, (error, statAndIsLink) => {
|
||||
if (error) {
|
||||
return onError(error, done);
|
||||
return done(error);
|
||||
}
|
||||
|
||||
assert.ok(!statAndIsLink.isSymbolicLink);
|
||||
|
||||
extfs.statLink(symbolicLink, (error, statAndIsLink) => {
|
||||
if (error) {
|
||||
return onError(error, done);
|
||||
return done(error);
|
||||
}
|
||||
|
||||
assert.ok(statAndIsLink.isSymbolicLink);
|
||||
@@ -124,14 +123,14 @@ suite('Extfs', () => {
|
||||
assert.ok(!fs.existsSync(newDir));
|
||||
});
|
||||
|
||||
test('delSync - simple', function (done: () => void) {
|
||||
test('delSync - simple', function (done) {
|
||||
const id = uuid.generateUuid();
|
||||
const parentDir = path.join(os.tmpdir(), 'vsctests', id);
|
||||
const newDir = path.join(parentDir, 'extfs', id);
|
||||
|
||||
mkdirp(newDir, 493, error => {
|
||||
if (error) {
|
||||
return onError(error, done);
|
||||
return done(error);
|
||||
}
|
||||
|
||||
fs.writeFileSync(path.join(newDir, 'somefile.txt'), 'Contents');
|
||||
@@ -144,14 +143,14 @@ suite('Extfs', () => {
|
||||
}); // 493 = 0755
|
||||
});
|
||||
|
||||
test('delSync - recursive folder structure', function (done: () => void) {
|
||||
test('delSync - recursive folder structure', function (done) {
|
||||
const id = uuid.generateUuid();
|
||||
const parentDir = path.join(os.tmpdir(), 'vsctests', id);
|
||||
const newDir = path.join(parentDir, 'extfs', id);
|
||||
|
||||
mkdirp(newDir, 493, error => {
|
||||
if (error) {
|
||||
return onError(error, done);
|
||||
return done(error);
|
||||
}
|
||||
|
||||
fs.writeFileSync(path.join(newDir, 'somefile.txt'), 'Contents');
|
||||
@@ -167,7 +166,7 @@ suite('Extfs', () => {
|
||||
}); // 493 = 0755
|
||||
});
|
||||
|
||||
test('copy, move and delete', function (done: () => void) {
|
||||
test('copy, move and delete', function (done) {
|
||||
const id = uuid.generateUuid();
|
||||
const id2 = uuid.generateUuid();
|
||||
const sourceDir = require.toUrl('./fixtures');
|
||||
@@ -177,7 +176,7 @@ suite('Extfs', () => {
|
||||
|
||||
extfs.copy(sourceDir, targetDir, error => {
|
||||
if (error) {
|
||||
return onError(error, done);
|
||||
return done(error);
|
||||
}
|
||||
|
||||
assert.ok(fs.existsSync(targetDir));
|
||||
@@ -189,7 +188,7 @@ suite('Extfs', () => {
|
||||
|
||||
extfs.mv(targetDir, targetDir2, error => {
|
||||
if (error) {
|
||||
return onError(error, done);
|
||||
return done(error);
|
||||
}
|
||||
|
||||
assert.ok(!fs.existsSync(targetDir));
|
||||
@@ -202,7 +201,7 @@ suite('Extfs', () => {
|
||||
|
||||
extfs.mv(path.join(targetDir2, 'index.html'), path.join(targetDir2, 'index_moved.html'), error => {
|
||||
if (error) {
|
||||
return onError(error, done);
|
||||
return done(error);
|
||||
}
|
||||
|
||||
assert.ok(!fs.existsSync(path.join(targetDir2, 'index.html')));
|
||||
@@ -210,11 +209,11 @@ suite('Extfs', () => {
|
||||
|
||||
extfs.del(parentDir, os.tmpdir(), error => {
|
||||
if (error) {
|
||||
return onError(error, done);
|
||||
return done(error);
|
||||
}
|
||||
}, error => {
|
||||
if (error) {
|
||||
return onError(error, done);
|
||||
return done(error);
|
||||
}
|
||||
assert.ok(!fs.existsSync(parentDir));
|
||||
done();
|
||||
@@ -224,7 +223,7 @@ suite('Extfs', () => {
|
||||
});
|
||||
});
|
||||
|
||||
test('readdir', function (done: () => void) {
|
||||
test('readdir', function (done) {
|
||||
if (strings.canNormalize && typeof process.versions['electron'] !== 'undefined' /* needs electron */) {
|
||||
const id = uuid.generateUuid();
|
||||
const parentDir = path.join(os.tmpdir(), 'vsctests', id);
|
||||
@@ -232,7 +231,7 @@ suite('Extfs', () => {
|
||||
|
||||
mkdirp(newDir, 493, error => {
|
||||
if (error) {
|
||||
return onError(error, done);
|
||||
return done(error);
|
||||
}
|
||||
|
||||
assert.ok(fs.existsSync(newDir));
|
||||
@@ -248,7 +247,7 @@ suite('Extfs', () => {
|
||||
}
|
||||
});
|
||||
|
||||
test('writeFileAndFlush (string)', function (done: () => void) {
|
||||
test('writeFileAndFlush (string)', function (done) {
|
||||
const id = uuid.generateUuid();
|
||||
const parentDir = path.join(os.tmpdir(), 'vsctests', id);
|
||||
const newDir = path.join(parentDir, 'extfs', id);
|
||||
@@ -256,14 +255,14 @@ suite('Extfs', () => {
|
||||
|
||||
mkdirp(newDir, 493, error => {
|
||||
if (error) {
|
||||
return onError(error, done);
|
||||
return done(error);
|
||||
}
|
||||
|
||||
assert.ok(fs.existsSync(newDir));
|
||||
|
||||
extfs.writeFileAndFlush(testFile, 'Hello World', null, error => {
|
||||
if (error) {
|
||||
return onError(error, done);
|
||||
return done(error);
|
||||
}
|
||||
|
||||
assert.equal(fs.readFileSync(testFile), 'Hello World');
|
||||
@@ -272,7 +271,7 @@ suite('Extfs', () => {
|
||||
|
||||
extfs.writeFileAndFlush(testFile, largeString, null, error => {
|
||||
if (error) {
|
||||
return onError(error, done);
|
||||
return done(error);
|
||||
}
|
||||
|
||||
assert.equal(fs.readFileSync(testFile), largeString);
|
||||
@@ -283,7 +282,7 @@ suite('Extfs', () => {
|
||||
});
|
||||
});
|
||||
|
||||
test('writeFileAndFlush (stream)', function (done: () => void) {
|
||||
test('writeFileAndFlush (stream)', function (done) {
|
||||
const id = uuid.generateUuid();
|
||||
const parentDir = path.join(os.tmpdir(), 'vsctests', id);
|
||||
const newDir = path.join(parentDir, 'extfs', id);
|
||||
@@ -291,14 +290,14 @@ suite('Extfs', () => {
|
||||
|
||||
mkdirp(newDir, 493, error => {
|
||||
if (error) {
|
||||
return onError(error, done);
|
||||
return done(error);
|
||||
}
|
||||
|
||||
assert.ok(fs.existsSync(newDir));
|
||||
|
||||
extfs.writeFileAndFlush(testFile, toReadable('Hello World'), null, error => {
|
||||
if (error) {
|
||||
return onError(error, done);
|
||||
return done(error);
|
||||
}
|
||||
|
||||
assert.equal(fs.readFileSync(testFile), 'Hello World');
|
||||
@@ -307,7 +306,7 @@ suite('Extfs', () => {
|
||||
|
||||
extfs.writeFileAndFlush(testFile, toReadable(largeString), null, error => {
|
||||
if (error) {
|
||||
return onError(error, done);
|
||||
return done(error);
|
||||
}
|
||||
|
||||
assert.equal(fs.readFileSync(testFile), largeString);
|
||||
@@ -318,7 +317,7 @@ suite('Extfs', () => {
|
||||
});
|
||||
});
|
||||
|
||||
test('writeFileAndFlush (file stream)', function (done: () => void) {
|
||||
test('writeFileAndFlush (file stream)', function (done) {
|
||||
const id = uuid.generateUuid();
|
||||
const parentDir = path.join(os.tmpdir(), 'vsctests', id);
|
||||
const sourceFile = require.toUrl('./fixtures/index.html');
|
||||
@@ -327,14 +326,14 @@ suite('Extfs', () => {
|
||||
|
||||
mkdirp(newDir, 493, error => {
|
||||
if (error) {
|
||||
return onError(error, done);
|
||||
return done(error);
|
||||
}
|
||||
|
||||
assert.ok(fs.existsSync(newDir));
|
||||
|
||||
extfs.writeFileAndFlush(testFile, fs.createReadStream(sourceFile), null, error => {
|
||||
if (error) {
|
||||
return onError(error, done);
|
||||
return done(error);
|
||||
}
|
||||
|
||||
assert.equal(fs.readFileSync(testFile).toString(), fs.readFileSync(sourceFile).toString());
|
||||
@@ -344,7 +343,7 @@ suite('Extfs', () => {
|
||||
});
|
||||
});
|
||||
|
||||
test('writeFileAndFlush (string, error handling)', function (done: () => void) {
|
||||
test('writeFileAndFlush (string, error handling)', function (done) {
|
||||
const id = uuid.generateUuid();
|
||||
const parentDir = path.join(os.tmpdir(), 'vsctests', id);
|
||||
const newDir = path.join(parentDir, 'extfs', id);
|
||||
@@ -352,7 +351,7 @@ suite('Extfs', () => {
|
||||
|
||||
mkdirp(newDir, 493, error => {
|
||||
if (error) {
|
||||
return onError(error, done);
|
||||
return done(error);
|
||||
}
|
||||
|
||||
assert.ok(fs.existsSync(newDir));
|
||||
@@ -361,7 +360,7 @@ suite('Extfs', () => {
|
||||
|
||||
extfs.writeFileAndFlush(testFile, 'Hello World', null, error => {
|
||||
if (!error) {
|
||||
return onError(new Error('Expected error for writing to readonly file'), done);
|
||||
return done(new Error('Expected error for writing to readonly file'));
|
||||
}
|
||||
|
||||
extfs.del(parentDir, os.tmpdir(), done, ignore);
|
||||
@@ -369,7 +368,7 @@ suite('Extfs', () => {
|
||||
});
|
||||
});
|
||||
|
||||
test('writeFileAndFlush (stream, error handling EISDIR)', function (done: () => void) {
|
||||
test('writeFileAndFlush (stream, error handling EISDIR)', function (done) {
|
||||
const id = uuid.generateUuid();
|
||||
const parentDir = path.join(os.tmpdir(), 'vsctests', id);
|
||||
const newDir = path.join(parentDir, 'extfs', id);
|
||||
@@ -377,7 +376,7 @@ suite('Extfs', () => {
|
||||
|
||||
mkdirp(newDir, 493, error => {
|
||||
if (error) {
|
||||
return onError(error, done);
|
||||
return done(error);
|
||||
}
|
||||
|
||||
assert.ok(fs.existsSync(newDir));
|
||||
@@ -387,7 +386,7 @@ suite('Extfs', () => {
|
||||
const readable = toReadable('Hello World');
|
||||
extfs.writeFileAndFlush(testFile, readable, null, error => {
|
||||
if (!error || (<any>error).code !== 'EISDIR') {
|
||||
return onError(new Error('Expected EISDIR error for writing to folder but got: ' + (error ? (<any>error).code : 'no error')), done);
|
||||
return done(new Error('Expected EISDIR error for writing to folder but got: ' + (error ? (<any>error).code : 'no error')));
|
||||
}
|
||||
|
||||
// verify that the stream is still consumable (for https://github.com/Microsoft/vscode/issues/42542)
|
||||
@@ -398,7 +397,7 @@ suite('Extfs', () => {
|
||||
});
|
||||
});
|
||||
|
||||
test('writeFileAndFlush (stream, error handling READERROR)', function (done: () => void) {
|
||||
test('writeFileAndFlush (stream, error handling READERROR)', function (done) {
|
||||
const id = uuid.generateUuid();
|
||||
const parentDir = path.join(os.tmpdir(), 'vsctests', id);
|
||||
const newDir = path.join(parentDir, 'extfs', id);
|
||||
@@ -406,14 +405,14 @@ suite('Extfs', () => {
|
||||
|
||||
mkdirp(newDir, 493, error => {
|
||||
if (error) {
|
||||
return onError(error, done);
|
||||
return done(error);
|
||||
}
|
||||
|
||||
assert.ok(fs.existsSync(newDir));
|
||||
|
||||
extfs.writeFileAndFlush(testFile, toReadable('Hello World', true /* throw error */), null, error => {
|
||||
if (!error || error.message !== readError) {
|
||||
return onError(new Error('Expected error for writing to folder'), done);
|
||||
return done(new Error('Expected error for writing to folder'));
|
||||
}
|
||||
|
||||
extfs.del(parentDir, os.tmpdir(), done, ignore);
|
||||
@@ -421,7 +420,7 @@ suite('Extfs', () => {
|
||||
});
|
||||
});
|
||||
|
||||
test('writeFileAndFlush (stream, error handling EACCES)', function (done: () => void) {
|
||||
test('writeFileAndFlush (stream, error handling EACCES)', function (done) {
|
||||
if (isLinux) {
|
||||
return done(); // somehow this test fails on Linux in our TFS builds
|
||||
}
|
||||
@@ -433,7 +432,7 @@ suite('Extfs', () => {
|
||||
|
||||
mkdirp(newDir, 493, error => {
|
||||
if (error) {
|
||||
return onError(error, done);
|
||||
return done(error);
|
||||
}
|
||||
|
||||
assert.ok(fs.existsSync(newDir));
|
||||
@@ -443,7 +442,7 @@ suite('Extfs', () => {
|
||||
|
||||
extfs.writeFileAndFlush(testFile, toReadable('Hello World'), null, error => {
|
||||
if (!error || !((<any>error).code !== 'EACCES' || (<any>error).code !== 'EPERM')) {
|
||||
return onError(new Error('Expected EACCES/EPERM error for writing to folder but got: ' + (error ? (<any>error).code : 'no error')), done);
|
||||
return done(new Error('Expected EACCES/EPERM error for writing to folder but got: ' + (error ? (<any>error).code : 'no error')));
|
||||
}
|
||||
|
||||
extfs.del(parentDir, os.tmpdir(), done, ignore);
|
||||
@@ -451,7 +450,7 @@ suite('Extfs', () => {
|
||||
});
|
||||
});
|
||||
|
||||
test('writeFileAndFlush (file stream, error handling)', function (done: () => void) {
|
||||
test('writeFileAndFlush (file stream, error handling)', function (done) {
|
||||
const id = uuid.generateUuid();
|
||||
const parentDir = path.join(os.tmpdir(), 'vsctests', id);
|
||||
const sourceFile = require.toUrl('./fixtures/index.html');
|
||||
@@ -460,7 +459,7 @@ suite('Extfs', () => {
|
||||
|
||||
mkdirp(newDir, 493, error => {
|
||||
if (error) {
|
||||
return onError(error, done);
|
||||
return done(error);
|
||||
}
|
||||
|
||||
assert.ok(fs.existsSync(newDir));
|
||||
@@ -469,7 +468,7 @@ suite('Extfs', () => {
|
||||
|
||||
extfs.writeFileAndFlush(testFile, fs.createReadStream(sourceFile), null, error => {
|
||||
if (!error) {
|
||||
return onError(new Error('Expected error for writing to folder'), done);
|
||||
return done(new Error('Expected error for writing to folder'));
|
||||
}
|
||||
|
||||
extfs.del(parentDir, os.tmpdir(), done, ignore);
|
||||
@@ -477,7 +476,7 @@ suite('Extfs', () => {
|
||||
});
|
||||
});
|
||||
|
||||
test('writeFileAndFlushSync', function (done: () => void) {
|
||||
test('writeFileAndFlushSync', function (done) {
|
||||
const id = uuid.generateUuid();
|
||||
const parentDir = path.join(os.tmpdir(), 'vsctests', id);
|
||||
const newDir = path.join(parentDir, 'extfs', id);
|
||||
@@ -485,7 +484,7 @@ suite('Extfs', () => {
|
||||
|
||||
mkdirp(newDir, 493, error => {
|
||||
if (error) {
|
||||
return onError(error, done);
|
||||
return done(error);
|
||||
}
|
||||
|
||||
assert.ok(fs.existsSync(newDir));
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
'use strict';
|
||||
|
||||
import * as assert from 'assert';
|
||||
import flow = require('vs/base/node/flow');
|
||||
import * as flow from 'vs/base/node/flow';
|
||||
|
||||
const loop = flow.loop;
|
||||
const sequence = flow.sequence;
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
import * as assert from 'assert';
|
||||
import * as path from 'path';
|
||||
import glob = require('vs/base/common/glob');
|
||||
import * as glob from 'vs/base/common/glob';
|
||||
import { isWindows } from 'vs/base/common/platform';
|
||||
|
||||
suite('Glob', () => {
|
||||
|
||||
@@ -1,91 +0,0 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
'use strict';
|
||||
|
||||
import assert = require('assert');
|
||||
|
||||
import mimeCommon = require('vs/base/common/mime');
|
||||
import mime = require('vs/base/node/mime');
|
||||
import { readExactlyByFile } from 'vs/base/node/stream';
|
||||
|
||||
suite('Mime', () => {
|
||||
|
||||
test('detectMimesFromFile (JSON saved as PNG)', function (done: (err?: any) => void) {
|
||||
const file = require.toUrl('./fixtures/some.json.png');
|
||||
|
||||
readExactlyByFile(file, 512).then(buffer => {
|
||||
const mimes = mime.detectMimeAndEncodingFromBuffer(buffer);
|
||||
assert.deepEqual(mimes.mimes, ['text/plain']);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
test('detectMimesFromFile (PNG saved as TXT)', function (done: (err?: any) => void) {
|
||||
mimeCommon.registerTextMime({ id: 'text', mime: 'text/plain', extension: '.txt' });
|
||||
const file = require.toUrl('./fixtures/some.png.txt');
|
||||
readExactlyByFile(file, 512).then(buffer => {
|
||||
const mimes = mime.detectMimeAndEncodingFromBuffer(buffer);
|
||||
assert.deepEqual(mimes.mimes, ['application/octet-stream']);
|
||||
done();
|
||||
}, done);
|
||||
});
|
||||
|
||||
test('detectMimesFromFile (XML saved as PNG)', function (done: (err?: any) => void) {
|
||||
const file = require.toUrl('./fixtures/some.xml.png');
|
||||
readExactlyByFile(file, 512).then(buffer => {
|
||||
const mimes = mime.detectMimeAndEncodingFromBuffer(buffer);
|
||||
assert.deepEqual(mimes.mimes, ['text/plain']);
|
||||
done();
|
||||
}, done);
|
||||
});
|
||||
|
||||
test('detectMimesFromFile (QWOFF saved as TXT)', function (done: (err?: any) => void) {
|
||||
const file = require.toUrl('./fixtures/some.qwoff.txt');
|
||||
readExactlyByFile(file, 512).then(buffer => {
|
||||
const mimes = mime.detectMimeAndEncodingFromBuffer(buffer);
|
||||
assert.deepEqual(mimes.mimes, ['application/octet-stream']);
|
||||
done();
|
||||
}, done);
|
||||
});
|
||||
|
||||
test('detectMimesFromFile (CSS saved as QWOFF)', function (done: (err?: any) => void) {
|
||||
const file = require.toUrl('./fixtures/some.css.qwoff');
|
||||
readExactlyByFile(file, 512).then(buffer => {
|
||||
const mimes = mime.detectMimeAndEncodingFromBuffer(buffer);
|
||||
assert.deepEqual(mimes.mimes, ['text/plain']);
|
||||
done();
|
||||
}, done);
|
||||
});
|
||||
|
||||
test('detectMimesFromFile (PDF)', function (done: () => void) {
|
||||
const file = require.toUrl('./fixtures/some.pdf');
|
||||
readExactlyByFile(file, 512).then(buffer => {
|
||||
const mimes = mime.detectMimeAndEncodingFromBuffer(buffer);
|
||||
assert.deepEqual(mimes.mimes, ['application/octet-stream']);
|
||||
done();
|
||||
}, done);
|
||||
});
|
||||
|
||||
test('autoGuessEncoding (ShiftJIS)', function (done: () => void) {
|
||||
const file = require.toUrl('./fixtures/some.shiftjis.txt');
|
||||
readExactlyByFile(file, 512 * 8).then(buffer => {
|
||||
mime.detectMimeAndEncodingFromBuffer(buffer, true).then(mimes => {
|
||||
assert.equal(mimes.encoding, 'shiftjis');
|
||||
done();
|
||||
});
|
||||
}, done);
|
||||
});
|
||||
|
||||
test('autoGuessEncoding (CP1252)', function (done: () => void) {
|
||||
const file = require.toUrl('./fixtures/some.cp1252.txt');
|
||||
readExactlyByFile(file, 512 * 8).then(buffer => {
|
||||
mime.detectMimeAndEncodingFromBuffer(buffer, true).then(mimes => {
|
||||
assert.equal(mimes.encoding, 'windows1252');
|
||||
done();
|
||||
});
|
||||
}, done);
|
||||
});
|
||||
});
|
||||
@@ -6,43 +6,36 @@
|
||||
|
||||
import { TPromise } from 'vs/base/common/winjs.base';
|
||||
|
||||
import assert = require('assert');
|
||||
import os = require('os');
|
||||
import * as assert from 'assert';
|
||||
import * as os from 'os';
|
||||
|
||||
import path = require('path');
|
||||
import fs = require('fs');
|
||||
import * as path from 'path';
|
||||
import * as fs from 'fs';
|
||||
|
||||
import uuid = require('vs/base/common/uuid');
|
||||
import extfs = require('vs/base/node/extfs');
|
||||
import { onError } from 'vs/base/test/common/utils';
|
||||
import * as uuid from 'vs/base/common/uuid';
|
||||
import * as pfs from 'vs/base/node/pfs';
|
||||
import { timeout } from 'vs/base/common/async';
|
||||
|
||||
suite('PFS', () => {
|
||||
|
||||
test('writeFile', function (done: () => void) {
|
||||
test('writeFile', function () {
|
||||
const id = uuid.generateUuid();
|
||||
const parentDir = path.join(os.tmpdir(), 'vsctests', id);
|
||||
const newDir = path.join(parentDir, 'pfs', id);
|
||||
const testFile = path.join(newDir, 'writefile.txt');
|
||||
|
||||
const onMkdirp = error => {
|
||||
if (error) {
|
||||
return onError(error, done);
|
||||
}
|
||||
|
||||
return pfs.mkdirp(newDir, 493).then(() => {
|
||||
assert.ok(fs.existsSync(newDir));
|
||||
|
||||
pfs.writeFile(testFile, 'Hello World', null).done(() => {
|
||||
return pfs.writeFile(testFile, 'Hello World', null).then(() => {
|
||||
assert.equal(fs.readFileSync(testFile), 'Hello World');
|
||||
|
||||
extfs.del(parentDir, os.tmpdir(), () => { }, done);
|
||||
}, error => onError(error, done));
|
||||
};
|
||||
|
||||
pfs.mkdirp(newDir, 493).done(() => onMkdirp(null), error => onMkdirp(error));
|
||||
return pfs.del(parentDir, os.tmpdir());
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
test('writeFile - parallel write on different files works', function (done: () => void) {
|
||||
test('writeFile - parallel write on different files works', function () {
|
||||
const id = uuid.generateUuid();
|
||||
const parentDir = path.join(os.tmpdir(), 'vsctests', id);
|
||||
const newDir = path.join(parentDir, 'pfs', id);
|
||||
@@ -52,106 +45,80 @@ suite('PFS', () => {
|
||||
const testFile4 = path.join(newDir, 'writefile4.txt');
|
||||
const testFile5 = path.join(newDir, 'writefile5.txt');
|
||||
|
||||
const onMkdirp = error => {
|
||||
if (error) {
|
||||
return onError(error, done);
|
||||
}
|
||||
|
||||
return pfs.mkdirp(newDir, 493).then(() => {
|
||||
assert.ok(fs.existsSync(newDir));
|
||||
|
||||
TPromise.join([
|
||||
return TPromise.join([
|
||||
pfs.writeFile(testFile1, 'Hello World 1', null),
|
||||
pfs.writeFile(testFile2, 'Hello World 2', null),
|
||||
pfs.writeFile(testFile3, 'Hello World 3', null),
|
||||
pfs.writeFile(testFile4, 'Hello World 4', null),
|
||||
pfs.writeFile(testFile5, 'Hello World 5', null)
|
||||
]).done(() => {
|
||||
]).then(() => {
|
||||
assert.equal(fs.readFileSync(testFile1), 'Hello World 1');
|
||||
assert.equal(fs.readFileSync(testFile2), 'Hello World 2');
|
||||
assert.equal(fs.readFileSync(testFile3), 'Hello World 3');
|
||||
assert.equal(fs.readFileSync(testFile4), 'Hello World 4');
|
||||
assert.equal(fs.readFileSync(testFile5), 'Hello World 5');
|
||||
|
||||
extfs.del(parentDir, os.tmpdir(), () => { }, done);
|
||||
}, error => onError(error, done));
|
||||
};
|
||||
|
||||
pfs.mkdirp(newDir, 493).done(() => onMkdirp(null), error => onMkdirp(error));
|
||||
return pfs.del(parentDir, os.tmpdir());
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
test('writeFile - parallel write on same files works and is sequentalized', function (done: () => void) {
|
||||
test('writeFile - parallel write on same files works and is sequentalized', function () {
|
||||
const id = uuid.generateUuid();
|
||||
const parentDir = path.join(os.tmpdir(), 'vsctests', id);
|
||||
const newDir = path.join(parentDir, 'pfs', id);
|
||||
const testFile = path.join(newDir, 'writefile.txt');
|
||||
|
||||
const onMkdirp = error => {
|
||||
if (error) {
|
||||
return onError(error, done);
|
||||
}
|
||||
|
||||
return pfs.mkdirp(newDir, 493).then(() => {
|
||||
assert.ok(fs.existsSync(newDir));
|
||||
|
||||
TPromise.join([
|
||||
return TPromise.join([
|
||||
pfs.writeFile(testFile, 'Hello World 1', null),
|
||||
pfs.writeFile(testFile, 'Hello World 2', null),
|
||||
TPromise.timeout(10).then(() => pfs.writeFile(testFile, 'Hello World 3', null)),
|
||||
timeout(10).then(() => pfs.writeFile(testFile, 'Hello World 3', null)),
|
||||
pfs.writeFile(testFile, 'Hello World 4', null),
|
||||
TPromise.timeout(10).then(() => pfs.writeFile(testFile, 'Hello World 5', null))
|
||||
]).done(() => {
|
||||
timeout(10).then(() => pfs.writeFile(testFile, 'Hello World 5', null))
|
||||
]).then(() => {
|
||||
assert.equal(fs.readFileSync(testFile), 'Hello World 5');
|
||||
|
||||
extfs.del(parentDir, os.tmpdir(), () => { }, done);
|
||||
}, error => onError(error, done));
|
||||
};
|
||||
|
||||
pfs.mkdirp(newDir, 493).done(() => onMkdirp(null), error => onMkdirp(error));
|
||||
return pfs.del(parentDir, os.tmpdir());
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
test('rimraf - simple', function (done: () => void) {
|
||||
test('rimraf - simple', function () {
|
||||
const id = uuid.generateUuid();
|
||||
const parentDir = path.join(os.tmpdir(), 'vsctests', id);
|
||||
const newDir = path.join(parentDir, 'extfs', id);
|
||||
|
||||
const onMkdirp = error => {
|
||||
if (error) {
|
||||
return onError(error, done);
|
||||
}
|
||||
|
||||
return pfs.mkdirp(newDir, 493).then(() => {
|
||||
fs.writeFileSync(path.join(newDir, 'somefile.txt'), 'Contents');
|
||||
fs.writeFileSync(path.join(newDir, 'someOtherFile.txt'), 'Contents');
|
||||
|
||||
pfs.rimraf(newDir).then(() => {
|
||||
return pfs.rimraf(newDir).then(() => {
|
||||
assert.ok(!fs.existsSync(newDir));
|
||||
done();
|
||||
}, error => onError(error, done));
|
||||
};
|
||||
|
||||
pfs.mkdirp(newDir, 493).done(() => onMkdirp(null), error => onMkdirp(error));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
test('rimraf - recursive folder structure', function (done: () => void) {
|
||||
test('rimraf - recursive folder structure', function () {
|
||||
const id = uuid.generateUuid();
|
||||
const parentDir = path.join(os.tmpdir(), 'vsctests', id);
|
||||
const newDir = path.join(parentDir, 'extfs', id);
|
||||
|
||||
const onMkdirp = error => {
|
||||
if (error) {
|
||||
return onError(error, done);
|
||||
}
|
||||
|
||||
return pfs.mkdirp(newDir, 493).then(() => {
|
||||
fs.writeFileSync(path.join(newDir, 'somefile.txt'), 'Contents');
|
||||
fs.writeFileSync(path.join(newDir, 'someOtherFile.txt'), 'Contents');
|
||||
|
||||
fs.mkdirSync(path.join(newDir, 'somefolder'));
|
||||
fs.writeFileSync(path.join(newDir, 'somefolder', 'somefile.txt'), 'Contents');
|
||||
|
||||
pfs.rimraf(newDir).then(() => {
|
||||
return pfs.rimraf(newDir).then(() => {
|
||||
assert.ok(!fs.existsSync(newDir));
|
||||
done();
|
||||
}, error => onError(error, done));
|
||||
};
|
||||
|
||||
pfs.mkdirp(newDir, 493).done(() => onMkdirp(null), error => onMkdirp(error));
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -7,10 +7,10 @@
|
||||
|
||||
import * as assert from 'assert';
|
||||
import * as net from 'net';
|
||||
import ports = require('vs/base/node/ports');
|
||||
import * as ports from 'vs/base/node/ports';
|
||||
|
||||
suite('Ports', () => {
|
||||
test('Finds a free port (no timeout)', function (done: () => void) {
|
||||
test('Finds a free port (no timeout)', function (done) {
|
||||
this.timeout(1000 * 10); // higher timeout for this test
|
||||
|
||||
if (process.env['VSCODE_PID']) {
|
||||
@@ -31,8 +31,8 @@ suite('Ports', () => {
|
||||
server.close();
|
||||
|
||||
done();
|
||||
});
|
||||
}, err => done(err));
|
||||
});
|
||||
});
|
||||
}, err => done(err));
|
||||
});
|
||||
});
|
||||
|
||||
@@ -5,9 +5,9 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
import processes = require('vs/base/node/processes');
|
||||
import * as processes from 'vs/base/node/processes';
|
||||
|
||||
const sender = processes.createQueuedSender(process);
|
||||
const sender = processes.createQueuedSender(<any>process);
|
||||
|
||||
process.on('message', msg => {
|
||||
sender.send(msg);
|
||||
|
||||
@@ -5,9 +5,9 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
import processes = require('vs/base/node/processes');
|
||||
import * as processes from 'vs/base/node/processes';
|
||||
|
||||
const sender = processes.createQueuedSender(process);
|
||||
const sender = processes.createQueuedSender(<any>process);
|
||||
|
||||
process.on('message', msg => {
|
||||
sender.send(msg);
|
||||
|
||||
@@ -10,7 +10,7 @@ import * as cp from 'child_process';
|
||||
import * as objects from 'vs/base/common/objects';
|
||||
import * as platform from 'vs/base/common/platform';
|
||||
import URI from 'vs/base/common/uri';
|
||||
import processes = require('vs/base/node/processes');
|
||||
import * as processes from 'vs/base/node/processes';
|
||||
|
||||
function fork(id: string): cp.ChildProcess {
|
||||
const opts: any = {
|
||||
|
||||
@@ -5,47 +5,42 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
import assert = require('assert');
|
||||
import * as assert from 'assert';
|
||||
|
||||
import stream = require('vs/base/node/stream');
|
||||
import * as stream from 'vs/base/node/stream';
|
||||
|
||||
suite('Stream', () => {
|
||||
test('readExactlyByFile - ANSI', function (done: (err?) => void) {
|
||||
test('readExactlyByFile - ANSI', function () {
|
||||
const file = require.toUrl('./fixtures/file.css');
|
||||
|
||||
stream.readExactlyByFile(file, 10).then(({ buffer, bytesRead }) => {
|
||||
return stream.readExactlyByFile(file, 10).then(({ buffer, bytesRead }) => {
|
||||
assert.equal(bytesRead, 10);
|
||||
assert.equal(buffer.toString(), '/*--------');
|
||||
done();
|
||||
}, done);
|
||||
});
|
||||
});
|
||||
|
||||
test('readExactlyByFile - empty', function (done: (err?: any) => void) {
|
||||
test('readExactlyByFile - empty', function () {
|
||||
const file = require.toUrl('./fixtures/empty.txt');
|
||||
|
||||
stream.readExactlyByFile(file, 10).then(({ bytesRead }) => {
|
||||
return stream.readExactlyByFile(file, 10).then(({ bytesRead }) => {
|
||||
assert.equal(bytesRead, 0);
|
||||
done();
|
||||
}, done);
|
||||
});
|
||||
});
|
||||
|
||||
test('readToMatchingString - ANSI', function (done: (err?: any) => void) {
|
||||
test('readToMatchingString - ANSI', function () {
|
||||
const file = require.toUrl('./fixtures/file.css');
|
||||
|
||||
stream.readToMatchingString(file, '\n', 10, 100).then((result: string) => {
|
||||
return stream.readToMatchingString(file, '\n', 10, 100).then((result: string) => {
|
||||
// \r may be present on Windows
|
||||
assert.equal(result.replace('\r', ''), '/*---------------------------------------------------------------------------------------------');
|
||||
done();
|
||||
}, done);
|
||||
});
|
||||
});
|
||||
|
||||
test('readToMatchingString - empty', function (done: (err?: any) => void) {
|
||||
test('readToMatchingString - empty', function () {
|
||||
const file = require.toUrl('./fixtures/empty.txt');
|
||||
|
||||
stream.readToMatchingString(file, '\n', 10, 100).then((result: string) => {
|
||||
return stream.readToMatchingString(file, '\n', 10, 100).then((result: string) => {
|
||||
assert.equal(result, null);
|
||||
|
||||
done();
|
||||
}, done);
|
||||
});
|
||||
});
|
||||
});
|
||||
31
src/vs/base/test/node/utils.ts
Normal file
31
src/vs/base/test/node/utils.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
'use strict';
|
||||
|
||||
import { TPromise } from 'vs/base/common/winjs.base';
|
||||
import { generateUuid } from 'vs/base/common/uuid';
|
||||
import { join } from 'path';
|
||||
import { tmpdir } from 'os';
|
||||
import { mkdirp, del } from 'vs/base/node/pfs';
|
||||
|
||||
export interface ITestFileResult {
|
||||
testFile: string;
|
||||
cleanUp: () => TPromise<void>;
|
||||
}
|
||||
|
||||
export function testFile(folder: string, file: string): TPromise<ITestFileResult> {
|
||||
const id = generateUuid();
|
||||
const parentDir = join(tmpdir(), 'vsctests', id);
|
||||
const newDir = join(parentDir, 'config', id);
|
||||
const testFile = join(newDir, 'config.json');
|
||||
|
||||
return mkdirp(newDir, 493).then(() => {
|
||||
return {
|
||||
testFile,
|
||||
cleanUp: () => del(parentDir, tmpdir())
|
||||
} as ITestFileResult;
|
||||
});
|
||||
}
|
||||
@@ -12,6 +12,7 @@ import URI from 'vs/base/common/uri';
|
||||
import { extract } from 'vs/base/node/zip';
|
||||
import { generateUuid } from 'vs/base/common/uuid';
|
||||
import { rimraf, exists } from 'vs/base/node/pfs';
|
||||
import { NullLogService } from '../../../../platform/log/common/log';
|
||||
|
||||
const fixtures = URI.parse(require.toUrl('./fixtures')).fsPath;
|
||||
|
||||
@@ -21,7 +22,7 @@ suite('Zip', () => {
|
||||
const fixture = path.join(fixtures, 'extract.zip');
|
||||
const target = path.join(os.tmpdir(), generateUuid());
|
||||
|
||||
return extract(fixture, target)
|
||||
return extract(fixture, target, {}, new NullLogService())
|
||||
.then(() => exists(path.join(target, 'extension')))
|
||||
.then(exists => assert(exists))
|
||||
.then(() => rimraf(target));
|
||||
|
||||
Reference in New Issue
Block a user