mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-10-07 00:07:07 +00:00
WIP
This commit is contained in:
+39
-44
@@ -15,22 +15,22 @@ import { timeYear } from 'd3-time';
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
class NumCoercible {
|
||||
public a: number;
|
||||
a: number;
|
||||
|
||||
constructor(a: number) {
|
||||
this.a = a;
|
||||
}
|
||||
public valueOf() {
|
||||
valueOf() {
|
||||
return this.a;
|
||||
}
|
||||
}
|
||||
|
||||
class MixedObject {
|
||||
|
||||
public num: number;
|
||||
public str: string;
|
||||
public numeric: NumCoercible;
|
||||
public date: Date;
|
||||
num: number;
|
||||
str: string;
|
||||
numeric: NumCoercible;
|
||||
date: Date;
|
||||
|
||||
constructor(a: number, date: Date) {
|
||||
this.num = a;
|
||||
@@ -55,32 +55,32 @@ let mixedOrUndefinedExtent: [d3Array.Primitive | NumCoercible, d3Array.Primitive
|
||||
let dateOrUndefinedExtent: [Date, Date] | [undefined, undefined];
|
||||
|
||||
let numbersArray = [10, 20, 30, 40, 50];
|
||||
let numbersOrUndefinedArray = [10, 20, undefined, null, 40, 50];
|
||||
let stringyNumbersArray = ['10', '20', '30', '40', '50'];
|
||||
let numericArray = [new NumCoercible(10), new NumCoercible(20), new NumCoercible(30), new NumCoercible(40), new NumCoercible(50)];
|
||||
let dateArray = [new Date(2016, 6, 1), new Date(2016, 7, 30), new Date(2015, 3, 15)];
|
||||
let mixedObjectArray = [
|
||||
const numbersOrUndefinedArray = [10, 20, undefined, null, 40, 50];
|
||||
const stringyNumbersArray = ['10', '20', '30', '40', '50'];
|
||||
const numericArray = [new NumCoercible(10), new NumCoercible(20), new NumCoercible(30), new NumCoercible(40), new NumCoercible(50)];
|
||||
const dateArray = [new Date(2016, 6, 1), new Date(2016, 7, 30), new Date(2015, 3, 15)];
|
||||
const mixedObjectArray = [
|
||||
new MixedObject(10, new Date(2016, 6, 1)),
|
||||
new MixedObject(20, new Date(2016, 7, 30)),
|
||||
new MixedObject(30, new Date(2015, 3, 15)),
|
||||
new MixedObject(40, new Date(2014, 3, 15)),
|
||||
new MixedObject(50, new Date(2017, 4, 15))
|
||||
];
|
||||
let mixedObjectOrUndefinedArray = [...mixedObjectArray, undefined]
|
||||
const mixedObjectOrUndefinedArray = [...mixedObjectArray, undefined];
|
||||
|
||||
function accessorMixedObjectToNum(datum: MixedObject, index: number, array: Array<MixedObject>): number {
|
||||
function accessorMixedObjectToNum(datum: MixedObject, index: number, array: MixedObject[]): number {
|
||||
return datum.num;
|
||||
}
|
||||
|
||||
function accessorMixedObjectToStr(datum: MixedObject, index: number, array: Array<MixedObject>): string {
|
||||
function accessorMixedObjectToStr(datum: MixedObject, index: number, array: MixedObject[]): string {
|
||||
return datum.str;
|
||||
}
|
||||
|
||||
function accessorMixedObjectToNumeric(datum: MixedObject, index: number, array: Array<MixedObject>): NumCoercible {
|
||||
function accessorMixedObjectToNumeric(datum: MixedObject, index: number, array: MixedObject[]): NumCoercible {
|
||||
return datum.numeric;
|
||||
}
|
||||
|
||||
function accessorMixedObjectToDate(datum: MixedObject, index: number, array: Array<MixedObject>): Date {
|
||||
function accessorMixedObjectToDate(datum: MixedObject, index: number, array: MixedObject[]): Date {
|
||||
return datum.date;
|
||||
}
|
||||
|
||||
@@ -88,7 +88,7 @@ function accessorMixedObjectToNumOrUndefined(datum: MixedObject | undefined, ind
|
||||
return datum ? datum.num : undefined;
|
||||
}
|
||||
|
||||
function accessorMixedObjectToStrOrUndefined(datum: MixedObject | undefined, index: number, array: Array<MixedObject>): string | undefined | null {
|
||||
function accessorMixedObjectToStrOrUndefined(datum: MixedObject | undefined, index: number, array: MixedObject[]): string | undefined | null {
|
||||
return datum ? datum.str : undefined;
|
||||
}
|
||||
|
||||
@@ -210,17 +210,17 @@ numOrUndefined = d3Array.variance(mixedObjectOrUndefinedArray, accessorMixedObje
|
||||
|
||||
// scan() ----------------------------------------------------------------------
|
||||
|
||||
numOrUndefined = d3Array.scan(numbersArray)
|
||||
numOrUndefined = d3Array.scan(numbersArray);
|
||||
|
||||
numOrUndefined = d3Array.scan(mixedObjectArray, function (a, b) {
|
||||
let aElem: MixedObject = a;
|
||||
let bElem: MixedObject = b;
|
||||
numOrUndefined = d3Array.scan(mixedObjectArray, (a, b) => {
|
||||
const aElem: MixedObject = a;
|
||||
const bElem: MixedObject = b;
|
||||
return a.num - b.num;
|
||||
});
|
||||
|
||||
numOrUndefined = d3Array.scan(mixedObjectOrUndefinedArray, function (a, b) {
|
||||
let aElem: MixedObject | undefined = a;
|
||||
let bElem: MixedObject | undefined = b;
|
||||
numOrUndefined = d3Array.scan(mixedObjectOrUndefinedArray, (a, b) => {
|
||||
const aElem: MixedObject | undefined = a;
|
||||
const bElem: MixedObject | undefined = b;
|
||||
return a && b ? a.num - b.num : NaN;
|
||||
});
|
||||
|
||||
@@ -268,19 +268,16 @@ num = d3Array.bisect([new Date(2010, 1, 1), new Date(2011, 1, 1), new Date(2012,
|
||||
|
||||
// bisector() ------------------------------------------------------------------
|
||||
|
||||
mixedObjectArray.sort(function (a, b) { return a.date.valueOf() - b.date.valueOf(); });
|
||||
mixedObjectArray.sort((a, b) => a.date.valueOf() - b.date.valueOf());
|
||||
|
||||
let mixedObjectDateBisectorObject: d3Array.Bisector<MixedObject, Date>;
|
||||
|
||||
// define using accessor
|
||||
mixedObjectDateBisectorObject = d3Array.bisector<MixedObject, Date>(function (el) {
|
||||
return el.date;
|
||||
});
|
||||
mixedObjectDateBisectorObject = d3Array.bisector<MixedObject, Date>(el => el.date);
|
||||
|
||||
// define using comparator
|
||||
mixedObjectDateBisectorObject = d3Array.bisector<MixedObject, Date>(function (el, x) {
|
||||
return el.date.valueOf() - x.valueOf();
|
||||
});
|
||||
mixedObjectDateBisectorObject = d3Array.bisector<MixedObject, Date>((el, x) =>
|
||||
el.date.valueOf() - x.valueOf());
|
||||
|
||||
// bisect left
|
||||
num = mixedObjectDateBisectorObject.left(mixedObjectArray, new Date(2015, 3, 14));
|
||||
@@ -346,14 +343,14 @@ mergedArray = d3Array.permute(mergedArray, [1, 0, 2, 5, 3, 4, 6]);
|
||||
|
||||
// Getting an ordered array with object properties
|
||||
|
||||
let testObject = {
|
||||
const testObject = {
|
||||
val: 10,
|
||||
name: 'Test',
|
||||
when: new Date(),
|
||||
more: [10, 30, 40]
|
||||
};
|
||||
|
||||
let x: Array<number | string | Date | number[]> = d3Array.permute(testObject, ['name', 'val', 'when', 'more']);
|
||||
const x: Array<number | string | Date | number[]> = d3Array.permute(testObject, ['name', 'val', 'when', 'more']);
|
||||
|
||||
|
||||
// range() ---------------------------------------------------------------------
|
||||
@@ -412,7 +409,7 @@ testArrays = d3Array.zip(
|
||||
// Test Histogram
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
let tScale = scaleTime();
|
||||
const tScale = scaleTime();
|
||||
|
||||
// Create histogram generator ==================================================
|
||||
|
||||
@@ -426,10 +423,10 @@ testHistogram = d3Array.histogram<MixedObject, Date>();
|
||||
|
||||
// value(...) ------------------------------------------------------------------
|
||||
|
||||
testHistogram = testHistogram.value(function (d, i, data) {
|
||||
let datum: MixedObject = d; // d is of type MixedObject
|
||||
let index: number = i; // i is number
|
||||
let array: MixedObject[] = data; // data is of type MixedObject[]
|
||||
testHistogram = testHistogram.value((d, i, data) => {
|
||||
const datum: MixedObject = d; // d is of type MixedObject
|
||||
const index: number = i; // i is number
|
||||
const array: MixedObject[] = data; // data is of type MixedObject[]
|
||||
return datum.date;
|
||||
});
|
||||
|
||||
@@ -442,16 +439,14 @@ valueAccessorFn = testHistogram.value();
|
||||
testHistogram = testHistogram.domain([new Date(2014, 3, 15), new Date(2017, 4, 15)]);
|
||||
|
||||
// usage with scale domain:
|
||||
let domain = tScale.domain();
|
||||
const domain = tScale.domain();
|
||||
|
||||
testHistogram = testHistogram.domain([domain[0], domain[domain.length]]);
|
||||
|
||||
// testHistogram = testHistogram.domain(tScale.domain()); // fails, as scale domain is an array with possibly more than the two elements expected by histogram
|
||||
|
||||
// use with accessor function
|
||||
testHistogram = testHistogram.domain(function (values) {
|
||||
return [values[0], values[values.length]];
|
||||
});
|
||||
testHistogram = testHistogram.domain(values => [values[0], values[values.length]]);
|
||||
|
||||
// get current domain accessor function
|
||||
let domainAccessorFn: (values: Date[]) => [Date, Date];
|
||||
@@ -470,7 +465,7 @@ defaultHistogram = defaultHistogram.thresholds(d3Array.thresholdScott);
|
||||
testHistogram = testHistogram.thresholds([new Date(2015, 11, 15), new Date(2016, 6, 1), new Date(2016, 8, 30)]);
|
||||
|
||||
// with thresholds value array accessors
|
||||
testHistogram = testHistogram.thresholds(function (values: Date[], min: Date, max: Date) {
|
||||
testHistogram = testHistogram.thresholds((values: Date[], min: Date, max: Date) => {
|
||||
let thresholds: Date[];
|
||||
thresholds = [values[0], values[2], values[4]];
|
||||
return thresholds;
|
||||
@@ -498,7 +493,7 @@ let testBin: d3Array.Bin<MixedObject, Date>;
|
||||
testBin = testBins[0];
|
||||
|
||||
num = testBin.length; // defaultBin is array
|
||||
let mixedObject: MixedObject = testBin[0]; // with element type MixedObject
|
||||
const mixedObject: MixedObject = testBin[0]; // with element type MixedObject
|
||||
date = testBin.x0; // bin lower bound is Date
|
||||
date = testBin.x1; // bin upper bound is Date
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ import { syncHistory, routeReducer } from 'react-router-redux';
|
||||
const reducer = combineReducers({ routing: routeReducer });
|
||||
|
||||
// Sync dispatched route actions to the history
|
||||
const browserHistory = createHistory()
|
||||
const browserHistory = createHistory();
|
||||
const reduxRouterMiddleware = syncHistory(browserHistory);
|
||||
const createStoreWithMiddleware = applyMiddleware(reduxRouterMiddleware)(createStore);
|
||||
|
||||
|
||||
@@ -24,21 +24,21 @@ import {
|
||||
} from "react-router";
|
||||
import { createHistory, History } from "history";
|
||||
|
||||
const routerHistory = useRouterHistory(createHistory)({ basename: "/test" })
|
||||
const routerHistory = useRouterHistory(createHistory)({ basename: "/test" });
|
||||
|
||||
interface CustomHistory {
|
||||
test(): undefined;
|
||||
}
|
||||
|
||||
type CombinedHistory = History & CustomHistory
|
||||
type CombinedHistory = History & CustomHistory;
|
||||
|
||||
function createCustomHistory(history: History): CombinedHistory {
|
||||
return {
|
||||
...history,
|
||||
test() {}
|
||||
} as CombinedHistory
|
||||
} as CombinedHistory;
|
||||
}
|
||||
const customHistory = createCustomHistory(browserHistory)
|
||||
const customHistory = createCustomHistory(browserHistory);
|
||||
|
||||
|
||||
const NavLink = (props: LinkProps) => (
|
||||
@@ -141,13 +141,13 @@ ReactDOM.render((
|
||||
<Router history={ routerHistory }>
|
||||
<Route path="/" component={Master} />
|
||||
</Router>
|
||||
), document.body)
|
||||
), document.body);
|
||||
|
||||
ReactDOM.render((
|
||||
<Router history={ customHistory }>
|
||||
<Route path="/" component={Master} />
|
||||
</Router>
|
||||
), document.body)
|
||||
), document.body);
|
||||
|
||||
|
||||
const history = createMemoryHistory("baseurl");
|
||||
|
||||
+19
-19
@@ -14,12 +14,12 @@ function defaultDemo() {
|
||||
paginationClickable: true
|
||||
});
|
||||
|
||||
$('.arrow-left').on('click', function (e) {
|
||||
$('.arrow-left').on('click', e => {
|
||||
e.preventDefault();
|
||||
mySwiper.swipePrev();
|
||||
});
|
||||
|
||||
$('.arrow-right').on('click', function (e) {
|
||||
$('.arrow-right').on('click', e => {
|
||||
e.preventDefault();
|
||||
mySwiper.swipeNext();
|
||||
});
|
||||
@@ -40,7 +40,7 @@ function dynamicSlides() {
|
||||
pagination: '.pagination',
|
||||
paginationClickable: true
|
||||
});
|
||||
|
||||
|
||||
function randomColor() {
|
||||
var colors = ('blue red green orange pink').split(' ');
|
||||
return colors[Math.floor(Math.random() * colors.length)];
|
||||
@@ -48,41 +48,41 @@ function dynamicSlides() {
|
||||
|
||||
var count = 4;
|
||||
|
||||
$('.sdl-append').click(function (e) {
|
||||
$('.sdl-append').click(e => {
|
||||
e.preventDefault();
|
||||
mySwiper.appendSlide('<div class="title">Slide ' + (++count) + '</div>', 'swiper-slide ' + randomColor() + '-slide')
|
||||
mySwiper.appendSlide('<div class="title">Slide ' + (++count) + '</div>', 'swiper-slide ' + randomColor() + '-slide');
|
||||
});
|
||||
|
||||
$('.sdl-prepend').click(function (e) {
|
||||
$('.sdl-prepend').click(e => {
|
||||
e.preventDefault();
|
||||
mySwiper.prependSlide('<div class="title">Slide ' + (++count) + '</div>', 'swiper-slide ' + randomColor() + '-slide')
|
||||
mySwiper.prependSlide('<div class="title">Slide ' + (++count) + '</div>', 'swiper-slide ' + randomColor() + '-slide');
|
||||
});
|
||||
|
||||
$('.sdl-swap').click(function (e) {
|
||||
$('.sdl-swap').click(e => {
|
||||
e.preventDefault();
|
||||
mySwiper
|
||||
.getFirstSlide()
|
||||
.insertAfter(1);
|
||||
});
|
||||
|
||||
$('.sdl-insert').click(function (e) {
|
||||
$('.sdl-insert').click(e => {
|
||||
e.preventDefault();
|
||||
mySwiper
|
||||
.createSlide('<div class="title">Slide ' + (++count) + '</div>', 'swiper-slide ' + randomColor() + '-slide')
|
||||
.insertAfter(0);
|
||||
});
|
||||
|
||||
$('.sdl-remove1').click(function (e) {
|
||||
$('.sdl-remove1').click(e => {
|
||||
e.preventDefault();
|
||||
mySwiper.removeSlide(0);
|
||||
});
|
||||
|
||||
$('.sdl-removel').click(function (e) {
|
||||
$('.sdl-removel').click(e => {
|
||||
e.preventDefault();
|
||||
mySwiper.removeLastSlide();
|
||||
});
|
||||
|
||||
$('.sdl-remove2').click(function (e) {
|
||||
$('.sdl-remove2').click(e => {
|
||||
e.preventDefault();
|
||||
mySwiper.removeSlide(1);
|
||||
});
|
||||
@@ -108,7 +108,7 @@ function freeMode() {
|
||||
});
|
||||
}
|
||||
|
||||
// 06-carousel-mode.html
|
||||
// 06-carousel-mode.html
|
||||
function carouselMode() {
|
||||
var mySwiper = new Swiper('.swiper-container', {
|
||||
pagination: '.pagination',
|
||||
@@ -174,14 +174,14 @@ function tabs() {
|
||||
speed: 500
|
||||
});
|
||||
|
||||
$(".tabs a").on('touchstart mousedown', function (e) {
|
||||
$(".tabs a").on('touchstart mousedown', e => {
|
||||
e.preventDefault();
|
||||
$(".tabs .active").removeClass('active');
|
||||
$(this).addClass('active');
|
||||
tabsSwiper.swipeTo($(this).index());
|
||||
});
|
||||
|
||||
$(".tabs a").click(function (e) {
|
||||
$(".tabs a").click(e => {
|
||||
e.preventDefault();
|
||||
});
|
||||
}
|
||||
@@ -190,20 +190,20 @@ function tabs() {
|
||||
function tabsFeedback() {
|
||||
var tabsSwiper = new Swiper('.swiper-container', {
|
||||
speed: 500,
|
||||
onSlideChangeStart: function () {
|
||||
onSlideChangeStart: () => {
|
||||
$(".tabs .active").removeClass('active');
|
||||
$(".tabs a").eq(tabsSwiper.activeIndex).addClass('active');
|
||||
}
|
||||
});
|
||||
|
||||
$(".tabs a").on('touchstart mousedown', function (e) {
|
||||
$(".tabs a").on('touchstart mousedown', e => {
|
||||
e.preventDefault();
|
||||
$(".tabs .active").removeClass('active');
|
||||
$(this).addClass('active');
|
||||
tabsSwiper.swipeTo($(this).index());
|
||||
});
|
||||
|
||||
$(".tabs a").click(function (e) {
|
||||
$(".tabs a").click(e => {
|
||||
e.preventDefault();
|
||||
});
|
||||
}
|
||||
@@ -256,7 +256,7 @@ function visibilityApi() {
|
||||
});
|
||||
}
|
||||
|
||||
// 17 - responsive.html
|
||||
// 17 - responsive.html
|
||||
function responsive() {
|
||||
var mySwiper = new Swiper('.swiper-container', {
|
||||
pagination: '.pagination',
|
||||
|
||||
+76
-79
@@ -1,6 +1,3 @@
|
||||
/// <reference types="mocha" />
|
||||
/// <reference types="should" />
|
||||
|
||||
// from src
|
||||
|
||||
import * as vfs from 'vinyl-fs';
|
||||
@@ -22,16 +19,16 @@ import 'mocha';
|
||||
declare var gulp: any;
|
||||
declare var bufferStream: any;
|
||||
|
||||
var dataWrap = function (fn: any) {
|
||||
return function (data: any, enc: any, cb: any) {
|
||||
var dataWrap = (fn: any) => {
|
||||
return (data: any, enc: any, cb: any) => {
|
||||
fn(data);
|
||||
cb();
|
||||
};
|
||||
};
|
||||
|
||||
describe('source stream', function () {
|
||||
describe('source stream', () => {
|
||||
|
||||
it('should explode on invalid glob (empty)', function (done) {
|
||||
it('should explode on invalid glob (empty)', done => {
|
||||
var stream: any;
|
||||
try {
|
||||
stream = gulp.src();
|
||||
@@ -42,7 +39,7 @@ describe('source stream', function () {
|
||||
}
|
||||
});
|
||||
|
||||
it('should explode on invalid glob (number)', function (done) {
|
||||
it('should explode on invalid glob (number)', done => {
|
||||
var stream: any;
|
||||
try {
|
||||
stream = gulp.src(123);
|
||||
@@ -53,7 +50,7 @@ describe('source stream', function () {
|
||||
}
|
||||
});
|
||||
|
||||
it('should explode on invalid glob (empty array)', function (done) {
|
||||
it('should explode on invalid glob (empty array)', done => {
|
||||
var stream: any;
|
||||
try {
|
||||
stream = gulp.src([]);
|
||||
@@ -64,7 +61,7 @@ describe('source stream', function () {
|
||||
}
|
||||
});
|
||||
|
||||
it('should pass through writes', function (done) {
|
||||
it('should pass through writes', done => {
|
||||
var expectedPath = path.join(__dirname, "./fixtures/test.coffee");
|
||||
var expectedContent = fs.readFileSync(expectedPath);
|
||||
|
||||
@@ -75,7 +72,7 @@ describe('source stream', function () {
|
||||
contents: expectedContent
|
||||
});
|
||||
|
||||
var onEnd = function () {
|
||||
var onEnd = () => {
|
||||
buffered.length.should.equal(1);
|
||||
buffered[0].should.equal(expectedFile);
|
||||
bufEqual(buffered[0].contents, expectedContent).should.equal(true);
|
||||
@@ -91,11 +88,11 @@ describe('source stream', function () {
|
||||
stream.end();
|
||||
});
|
||||
|
||||
it('should glob a file with default settings', function (done) {
|
||||
it('should glob a file with default settings', done => {
|
||||
var expectedPath = path.join(__dirname, "./fixtures/test.coffee");
|
||||
var expectedContent = fs.readFileSync(expectedPath);
|
||||
|
||||
var onEnd = function () {
|
||||
var onEnd = () => {
|
||||
buffered.length.should.equal(1);
|
||||
should.exist(buffered[0].stat);
|
||||
buffered[0].path.should.equal(expectedPath);
|
||||
@@ -111,11 +108,11 @@ describe('source stream', function () {
|
||||
stream.pipe(bufferStream);
|
||||
});
|
||||
|
||||
it('should glob a file with default settings and relative cwd', function (done) {
|
||||
it('should glob a file with default settings and relative cwd', done => {
|
||||
var expectedPath = path.join(__dirname, "./fixtures/test.coffee");
|
||||
var expectedContent = fs.readFileSync(expectedPath);
|
||||
|
||||
var onEnd = function () {
|
||||
var onEnd = () => {
|
||||
buffered.length.should.equal(1);
|
||||
should.exist(buffered[0].stat);
|
||||
buffered[0].path.should.equal(expectedPath);
|
||||
@@ -131,10 +128,10 @@ describe('source stream', function () {
|
||||
stream.pipe(bufferStream);
|
||||
});
|
||||
|
||||
it('should glob a directory with default settings', function (done) {
|
||||
it('should glob a directory with default settings', done => {
|
||||
var expectedPath = path.join(__dirname, "./fixtures/wow");
|
||||
|
||||
var onEnd = function () {
|
||||
var onEnd = () => {
|
||||
buffered.length.should.equal(1);
|
||||
buffered[0].path.should.equal(expectedPath);
|
||||
buffered[0].isNull().should.equal(true);
|
||||
@@ -149,11 +146,11 @@ describe('source stream', function () {
|
||||
stream.pipe(bufferStream);
|
||||
});
|
||||
|
||||
it('should glob a file with with no contents', function (done) {
|
||||
it('should glob a file with with no contents', done => {
|
||||
var expectedPath = path.join(__dirname, "./fixtures/test.coffee");
|
||||
var expectedContent = fs.readFileSync(expectedPath);
|
||||
|
||||
var onEnd = function () {
|
||||
var onEnd = () => {
|
||||
buffered.length.should.equal(1);
|
||||
buffered[0].path.should.equal(expectedPath);
|
||||
buffered[0].isNull().should.equal(true);
|
||||
@@ -168,22 +165,22 @@ describe('source stream', function () {
|
||||
stream.pipe(bufferStream);
|
||||
});
|
||||
|
||||
it('should glob a file with streaming contents', function (done) {
|
||||
it('should glob a file with streaming contents', done => {
|
||||
var expectedPath = path.join(__dirname, "./fixtures/test.coffee");
|
||||
var expectedContent = fs.readFileSync(expectedPath);
|
||||
|
||||
var onEnd = function () {
|
||||
var onEnd = () => {
|
||||
buffered.length.should.equal(1);
|
||||
should.exist(buffered[0].stat);
|
||||
buffered[0].path.should.equal(expectedPath);
|
||||
buffered[0].isStream().should.equal(true);
|
||||
|
||||
var contentBuffer = new Buffer([]);
|
||||
var contentBufferStream = through(dataWrap(function (data: any) {
|
||||
var contentBufferStream = through(dataWrap((data: any) => {
|
||||
contentBuffer = Buffer.concat([contentBuffer, data]);
|
||||
}));
|
||||
buffered[0].contents.pipe(contentBufferStream);
|
||||
buffered[0].contents.once('end', function () {
|
||||
buffered[0].contents.once('end', () => {
|
||||
bufEqual(contentBuffer, expectedContent);
|
||||
done();
|
||||
});
|
||||
@@ -212,26 +209,26 @@ import rimraf = require('rimraf');
|
||||
// var should = require('should');
|
||||
// require('mocha');
|
||||
|
||||
var wipeOut = function (cb: any) {
|
||||
var wipeOut = (cb: any) => {
|
||||
rimraf(path.join(__dirname, "./out-fixtures/"), cb);
|
||||
};
|
||||
|
||||
var dataWrap = function (fn: any) {
|
||||
return function (data: any, enc: any, cb: any) {
|
||||
var dataWrap = (fn: any) => {
|
||||
return (data: any, enc: any, cb: any) => {
|
||||
fn(data);
|
||||
cb();
|
||||
};
|
||||
};
|
||||
|
||||
var realMode = function (n: any) {
|
||||
var realMode = (n: any) => {
|
||||
return n & parseInt("07777", 8);
|
||||
};
|
||||
|
||||
describe('dest stream', function () {
|
||||
describe('dest stream', () => {
|
||||
beforeEach(wipeOut);
|
||||
afterEach(wipeOut);
|
||||
|
||||
it('should explode on invalid folder', function (done) {
|
||||
it('should explode on invalid folder', done => {
|
||||
var stream: any;
|
||||
try {
|
||||
stream = gulp.dest();
|
||||
@@ -242,7 +239,7 @@ describe('dest stream', function () {
|
||||
}
|
||||
});
|
||||
|
||||
it('should pass through writes with cwd', function (done) {
|
||||
it('should pass through writes with cwd', done => {
|
||||
var inputPath = path.join(__dirname, "./fixtures/test.coffee");
|
||||
|
||||
var expectedFile = new File({
|
||||
@@ -252,7 +249,7 @@ describe('dest stream', function () {
|
||||
contents: null
|
||||
});
|
||||
|
||||
var onEnd = function () {
|
||||
var onEnd = () => {
|
||||
buffered.length.should.equal(1);
|
||||
buffered[0].should.equal(expectedFile);
|
||||
done();
|
||||
@@ -267,7 +264,7 @@ describe('dest stream', function () {
|
||||
stream.end();
|
||||
});
|
||||
|
||||
it('should pass through writes with default cwd', function (done) {
|
||||
it('should pass through writes with default cwd', done => {
|
||||
var inputPath = path.join(__dirname, "./fixtures/test.coffee");
|
||||
|
||||
var expectedFile = new File({
|
||||
@@ -277,7 +274,7 @@ describe('dest stream', function () {
|
||||
contents: null
|
||||
});
|
||||
|
||||
var onEnd = function () {
|
||||
var onEnd = () => {
|
||||
buffered.length.should.equal(1);
|
||||
buffered[0].should.equal(expectedFile);
|
||||
done();
|
||||
@@ -292,7 +289,7 @@ describe('dest stream', function () {
|
||||
stream.end();
|
||||
});
|
||||
|
||||
it('should not write null files', function (done) {
|
||||
it('should not write null files', done => {
|
||||
var inputPath = path.join(__dirname, "./fixtures/test.coffee");
|
||||
var inputBase = path.join(__dirname, "./fixtures/");
|
||||
var expectedPath = path.join(__dirname, "./out-fixtures/test.coffee");
|
||||
@@ -306,7 +303,7 @@ describe('dest stream', function () {
|
||||
contents: null
|
||||
});
|
||||
|
||||
var onEnd = function () {
|
||||
var onEnd = () => {
|
||||
buffered.length.should.equal(1);
|
||||
buffered[0].should.equal(expectedFile);
|
||||
buffered[0].cwd.should.equal(expectedCwd, 'cwd should have changed');
|
||||
@@ -325,7 +322,7 @@ describe('dest stream', function () {
|
||||
stream.end();
|
||||
});
|
||||
|
||||
it('should write buffer files to the right folder with relative cwd', function (done) {
|
||||
it('should write buffer files to the right folder with relative cwd', done => {
|
||||
var inputPath = path.join(__dirname, "./fixtures/test.coffee");
|
||||
var inputBase = path.join(__dirname, "./fixtures/");
|
||||
var expectedPath = path.join(__dirname, "./out-fixtures/test.coffee");
|
||||
@@ -340,7 +337,7 @@ describe('dest stream', function () {
|
||||
contents: expectedContents
|
||||
});
|
||||
|
||||
var onEnd = function () {
|
||||
var onEnd = () => {
|
||||
buffered.length.should.equal(1);
|
||||
buffered[0].should.equal(expectedFile);
|
||||
buffered[0].cwd.should.equal(expectedCwd, 'cwd should have changed');
|
||||
@@ -360,7 +357,7 @@ describe('dest stream', function () {
|
||||
stream.end();
|
||||
});
|
||||
|
||||
it('should write buffer files to the right folder', function (done) {
|
||||
it('should write buffer files to the right folder', done => {
|
||||
var inputPath = path.join(__dirname, "./fixtures/test.coffee");
|
||||
var inputBase = path.join(__dirname, "./fixtures/");
|
||||
var expectedPath = path.join(__dirname, "./out-fixtures/test.coffee");
|
||||
@@ -379,7 +376,7 @@ describe('dest stream', function () {
|
||||
}
|
||||
});
|
||||
|
||||
var onEnd = function () {
|
||||
var onEnd = () => {
|
||||
buffered.length.should.equal(1);
|
||||
buffered[0].should.equal(expectedFile);
|
||||
buffered[0].cwd.should.equal(expectedCwd, 'cwd should have changed');
|
||||
@@ -400,7 +397,7 @@ describe('dest stream', function () {
|
||||
stream.end();
|
||||
});
|
||||
|
||||
it('should write streaming files to the right folder', function (done) {
|
||||
it('should write streaming files to the right folder', done => {
|
||||
var inputPath = path.join(__dirname, "./fixtures/test.coffee");
|
||||
var inputBase = path.join(__dirname, "./fixtures/");
|
||||
var expectedPath = path.join(__dirname, "./out-fixtures/test.coffee");
|
||||
@@ -420,7 +417,7 @@ describe('dest stream', function () {
|
||||
}
|
||||
});
|
||||
|
||||
var onEnd = function () {
|
||||
var onEnd = () => {
|
||||
buffered.length.should.equal(1);
|
||||
buffered[0].should.equal(expectedFile);
|
||||
buffered[0].cwd.should.equal(expectedCwd, 'cwd should have changed');
|
||||
@@ -438,14 +435,14 @@ describe('dest stream', function () {
|
||||
bufferStream = through.obj(dataWrap(buffered.push.bind(buffered)), onEnd);
|
||||
stream.pipe(bufferStream);
|
||||
stream.write(expectedFile);
|
||||
setTimeout(function () {
|
||||
setTimeout(() => {
|
||||
contentStream.write(expectedContents);
|
||||
contentStream.end();
|
||||
}, 100);
|
||||
stream.end();
|
||||
});
|
||||
|
||||
it('should write directories to the right folder', function (done) {
|
||||
it('should write directories to the right folder', done => {
|
||||
var inputPath = path.join(__dirname, "./fixtures/test");
|
||||
var inputBase = path.join(__dirname, "./fixtures/");
|
||||
var expectedPath = path.join(__dirname, "./out-fixtures/test");
|
||||
@@ -464,7 +461,7 @@ describe('dest stream', function () {
|
||||
}
|
||||
});
|
||||
|
||||
var onEnd = function () {
|
||||
var onEnd = () => {
|
||||
buffered.length.should.equal(1);
|
||||
buffered[0].should.equal(expectedFile);
|
||||
buffered[0].cwd.should.equal(expectedCwd, 'cwd should have changed');
|
||||
@@ -485,7 +482,7 @@ describe('dest stream', function () {
|
||||
stream.end();
|
||||
});
|
||||
|
||||
it('should allow piping multiple dests in streaming mode', function (done) {
|
||||
it('should allow piping multiple dests in streaming mode', done => {
|
||||
var inputPath1 = path.join(__dirname, "./out-fixtures/multiple-first");
|
||||
var inputPath2 = path.join(__dirname, "./out-fixtures/multiple-second");
|
||||
var inputBase = path.join(__dirname, "./out-fixtures/");
|
||||
@@ -493,20 +490,20 @@ describe('dest stream', function () {
|
||||
var stream1 = vfs.dest('./out-fixtures/', { cwd: __dirname });
|
||||
var stream2 = vfs.dest('./out-fixtures/', { cwd: __dirname });
|
||||
var content = fs.readFileSync(srcPath);
|
||||
var rename = through.obj(function (file: any, _: any, next: any) {
|
||||
var rename = through.obj((file: any, _: any, next: any) => {
|
||||
file.path = inputPath2;
|
||||
this.push(file);
|
||||
next();
|
||||
});
|
||||
|
||||
stream1.on('data', function (file: any) {
|
||||
stream1.on('data', (file: any) => {
|
||||
file.path.should.equal(inputPath1);
|
||||
});
|
||||
|
||||
stream1.pipe(rename).pipe(stream2);
|
||||
stream2.on('data', function (file: any) {
|
||||
stream2.on('data', (file: any) => {
|
||||
file.path.should.equal(inputPath2);
|
||||
}).once('end', function () {
|
||||
}).once('end', () => {
|
||||
fs.readFileSync(inputPath1, 'utf8').should.equal(content.toString());
|
||||
fs.readFileSync(inputPath2, 'utf8').should.equal(content.toString());
|
||||
done();
|
||||
@@ -533,29 +530,29 @@ describe('dest stream', function () {
|
||||
var chmodSpy = spies.chmodSpy;
|
||||
var statSpy = spies.statSpy;
|
||||
|
||||
var wipeOut = function (cb: any) {
|
||||
var wipeOut = (cb: any) => {
|
||||
rimraf(path.join(__dirname, './out-fixtures/'), cb);
|
||||
spies.setError('false');
|
||||
statSpy.reset();
|
||||
chmodSpy.reset();
|
||||
};
|
||||
|
||||
var dataWrap = function (fn: any) {
|
||||
return function (data: any, enc: any, cb: any) {
|
||||
var dataWrap = (fn: any) => {
|
||||
return (data: any, enc: any, cb: any) => {
|
||||
fn(data);
|
||||
cb();
|
||||
};
|
||||
};
|
||||
|
||||
var realMode = function (n: any) {
|
||||
var realMode = (n: any) => {
|
||||
return n & parseInt("07777", 8);
|
||||
};
|
||||
|
||||
describe('symlink stream', function () {
|
||||
describe('symlink stream', () => {
|
||||
beforeEach(wipeOut);
|
||||
afterEach(wipeOut);
|
||||
|
||||
it('should explode on invalid folder', function (done: any) {
|
||||
it('should explode on invalid folder', (done: any) => {
|
||||
var stream: any;
|
||||
try {
|
||||
stream = gulp.symlink();
|
||||
@@ -566,7 +563,7 @@ describe('symlink stream', function () {
|
||||
}
|
||||
});
|
||||
|
||||
it('should pass through writes with cwd', function (done) {
|
||||
it('should pass through writes with cwd', done => {
|
||||
var inputPath = path.join(__dirname, './fixtures/test.coffee');
|
||||
|
||||
var expectedFile = new File({
|
||||
@@ -576,7 +573,7 @@ describe('symlink stream', function () {
|
||||
contents: null
|
||||
});
|
||||
|
||||
var onEnd = function () {
|
||||
var onEnd = () => {
|
||||
buffered.length.should.equal(1);
|
||||
buffered[0].should.equal(expectedFile);
|
||||
done();
|
||||
@@ -591,7 +588,7 @@ describe('symlink stream', function () {
|
||||
stream.end();
|
||||
});
|
||||
|
||||
it('should pass through writes with default cwd', function (done) {
|
||||
it('should pass through writes with default cwd', done => {
|
||||
var inputPath = path.join(__dirname, './fixtures/test.coffee');
|
||||
|
||||
var expectedFile = new File({
|
||||
@@ -601,7 +598,7 @@ describe('symlink stream', function () {
|
||||
contents: null
|
||||
});
|
||||
|
||||
var onEnd = function () {
|
||||
var onEnd = () => {
|
||||
buffered.length.should.equal(1);
|
||||
buffered[0].should.equal(expectedFile);
|
||||
done();
|
||||
@@ -616,7 +613,7 @@ describe('symlink stream', function () {
|
||||
stream.end();
|
||||
});
|
||||
|
||||
it('should make link to the right folder with relative cwd', function (done) {
|
||||
it('should make link to the right folder with relative cwd', done => {
|
||||
var inputPath = path.join(__dirname, './fixtures/test.coffee');
|
||||
var inputBase = path.join(__dirname, './fixtures/');
|
||||
var expectedPath = path.join(__dirname, './out-fixtures/test.coffee');
|
||||
@@ -631,7 +628,7 @@ describe('symlink stream', function () {
|
||||
contents: expectedContents
|
||||
});
|
||||
|
||||
var onEnd = function () {
|
||||
var onEnd = () => {
|
||||
buffered.length.should.equal(1);
|
||||
buffered[0].should.equal(expectedFile);
|
||||
buffered[0].cwd.should.equal(__dirname, 'cwd should have changed');
|
||||
@@ -652,7 +649,7 @@ describe('symlink stream', function () {
|
||||
stream.end();
|
||||
});
|
||||
|
||||
it('should write buffer files to the right folder with function and relative cwd', function (done) {
|
||||
it('should write buffer files to the right folder with function and relative cwd', done => {
|
||||
var inputPath = path.join(__dirname, './fixtures/test.coffee');
|
||||
var inputBase = path.join(__dirname, './fixtures/');
|
||||
var expectedPath = path.join(__dirname, './out-fixtures/test.coffee');
|
||||
@@ -667,7 +664,7 @@ describe('symlink stream', function () {
|
||||
contents: expectedContents
|
||||
});
|
||||
|
||||
var onEnd = function () {
|
||||
var onEnd = () => {
|
||||
buffered.length.should.equal(1);
|
||||
buffered[0].should.equal(expectedFile);
|
||||
buffered[0].cwd.should.equal(__dirname, 'cwd should have changed');
|
||||
@@ -679,7 +676,7 @@ describe('symlink stream', function () {
|
||||
done();
|
||||
};
|
||||
|
||||
var stream = vfs.symlink(function (file) {
|
||||
var stream = vfs.symlink(file => {
|
||||
should.exist(file);
|
||||
file.should.equal(expectedFile);
|
||||
return './out-fixtures';
|
||||
@@ -692,7 +689,7 @@ describe('symlink stream', function () {
|
||||
stream.end();
|
||||
});
|
||||
|
||||
it('should write buffer files to the right folder', function (done) {
|
||||
it('should write buffer files to the right folder', done => {
|
||||
var inputPath = path.join(__dirname, './fixtures/test.coffee');
|
||||
var inputBase = path.join(__dirname, './fixtures/');
|
||||
var expectedPath = path.join(__dirname, './out-fixtures/test.coffee');
|
||||
@@ -711,7 +708,7 @@ describe('symlink stream', function () {
|
||||
}
|
||||
});
|
||||
|
||||
var onEnd = function () {
|
||||
var onEnd = () => {
|
||||
buffered.length.should.equal(1);
|
||||
buffered[0].should.equal(expectedFile);
|
||||
buffered[0].cwd.should.equal(__dirname, 'cwd should have changed');
|
||||
@@ -732,7 +729,7 @@ describe('symlink stream', function () {
|
||||
stream.end();
|
||||
});
|
||||
|
||||
it('should write streaming files to the right folder', function (done) {
|
||||
it('should write streaming files to the right folder', done => {
|
||||
var inputPath = path.join(__dirname, './fixtures/test.coffee');
|
||||
var inputBase = path.join(__dirname, './fixtures/');
|
||||
var expectedPath = path.join(__dirname, './out-fixtures/test.coffee');
|
||||
@@ -752,7 +749,7 @@ describe('symlink stream', function () {
|
||||
}
|
||||
});
|
||||
|
||||
var onEnd = function () {
|
||||
var onEnd = () => {
|
||||
buffered.length.should.equal(1);
|
||||
buffered[0].should.equal(expectedFile);
|
||||
buffered[0].cwd.should.equal(__dirname, 'cwd should have changed');
|
||||
@@ -770,14 +767,14 @@ describe('symlink stream', function () {
|
||||
bufferStream = through.obj(dataWrap(buffered.push.bind(buffered)), onEnd);
|
||||
stream.pipe(bufferStream);
|
||||
stream.write(expectedFile);
|
||||
setTimeout(function () {
|
||||
setTimeout(() => {
|
||||
contentStream.write(expectedContents);
|
||||
contentStream.end();
|
||||
}, 100);
|
||||
stream.end();
|
||||
});
|
||||
|
||||
it('should write directories to the right folder', function (done) {
|
||||
it('should write directories to the right folder', done => {
|
||||
var inputPath = path.join(__dirname, './fixtures/wow');
|
||||
var inputBase = path.join(__dirname, './fixtures/');
|
||||
var expectedPath = path.join(__dirname, './out-fixtures/wow');
|
||||
@@ -796,7 +793,7 @@ describe('symlink stream', function () {
|
||||
}
|
||||
});
|
||||
|
||||
var onEnd = function () {
|
||||
var onEnd = () => {
|
||||
buffered.length.should.equal(1);
|
||||
buffered[0].should.equal(expectedFile);
|
||||
buffered[0].cwd.should.equal(__dirname, 'cwd should have changed');
|
||||
@@ -817,7 +814,7 @@ describe('symlink stream', function () {
|
||||
stream.end();
|
||||
});
|
||||
|
||||
it('should use different modes for files and directories', function (done) {
|
||||
it('should use different modes for files and directories', done => {
|
||||
var inputBase = path.join(__dirname, './fixtures');
|
||||
var inputPath = path.join(__dirname, './fixtures/wow/suchempty');
|
||||
var expectedBase = path.join(__dirname, './out-fixtures/wow');
|
||||
@@ -831,7 +828,7 @@ describe('symlink stream', function () {
|
||||
stat: fs.statSync(inputPath)
|
||||
});
|
||||
|
||||
var onEnd = function () {
|
||||
var onEnd = () => {
|
||||
realMode(fs.lstatSync(expectedBase).mode).should.equal(expectedDirMode);
|
||||
realMode(buffered[0].stat.mode).should.equal(expectedFileMode);
|
||||
done();
|
||||
@@ -851,7 +848,7 @@ describe('symlink stream', function () {
|
||||
stream.end();
|
||||
});
|
||||
|
||||
it('should report IO errors', function (done) {
|
||||
it('should report IO errors', done => {
|
||||
var inputPath = path.join(__dirname, './fixtures/test.coffee');
|
||||
var inputBase = path.join(__dirname, './fixtures/');
|
||||
var expectedPath = path.join(__dirname, './out-fixtures/test.coffee');
|
||||
@@ -874,19 +871,19 @@ describe('symlink stream', function () {
|
||||
fs.chmodSync(expectedBase, 0);
|
||||
|
||||
var stream = vfs.symlink('./out-fixtures/', { cwd: __dirname });
|
||||
stream.on('error', function (err: any) {
|
||||
stream.on('error', (err: any) => {
|
||||
err.code.should.equal('EACCES');
|
||||
done();
|
||||
});
|
||||
stream.write(expectedFile);
|
||||
});
|
||||
|
||||
['end', 'finish'].forEach(function (eventName) {
|
||||
it('should emit ' + eventName + ' event', function (done) {
|
||||
['end', 'finish'].forEach(eventName => {
|
||||
it('should emit ' + eventName + ' event', done => {
|
||||
var srcPath = path.join(__dirname, './fixtures/test.coffee');
|
||||
var stream = vfs.symlink('./out-fixtures/', { cwd: __dirname });
|
||||
|
||||
stream.on(eventName, function () {
|
||||
stream.on(eventName, () => {
|
||||
done();
|
||||
});
|
||||
|
||||
@@ -900,7 +897,7 @@ describe('symlink stream', function () {
|
||||
stream.end();
|
||||
});
|
||||
});
|
||||
it('should check if it"s a vinyl file', function () {
|
||||
it('should check if it"s a vinyl file', () => {
|
||||
var srcPath = path.join(__dirname, './fixtures/test.coffee');
|
||||
var options = {
|
||||
path: srcPath,
|
||||
|
||||
Reference in New Issue
Block a user