Skip to content

Commit e8abe8b

Browse files
Sergey DobrodeevAnatoly BolshakovEzzhevNikita
authored
[CopyFilesV2] Migrated to Node10 (#14710)
* [CopyFilesV2] Migrated to Node10 * Addressed code review points Co-authored-by: Anatoly Bolshakov <[email protected]> Co-authored-by: Nikita Ezzhev <[email protected]>
1 parent 392108a commit e8abe8b

File tree

15 files changed

+336
-4018
lines changed

15 files changed

+336
-4018
lines changed

Tasks/CopyFilesV2/Tests/L0.ts

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ describe('CopyFiles L0 Suite', function () {
1010

1111
after(() => { });
1212

13-
it('copy files from srcdir to destdir', (done: MochaDone) => {
13+
it('copy files from srcdir to destdir', (done: Mocha.Done) => {
1414
this.timeout(1000);
1515

1616
let testPath = path.join(__dirname, 'L0copyAllFiles.js');
@@ -50,7 +50,7 @@ describe('CopyFiles L0 Suite', function () {
5050
done();
5151
});
5252

53-
it('copy files from srcdir to destdir with brackets in src path', (done: MochaDone) => {
53+
it('copy files from srcdir to destdir with brackets in src path', (done: Mocha.Done) => {
5454
this.timeout(1000);
5555

5656
let testPath = path.join(__dirname, 'L0copyAllFilesWithBracketsInSrcPath.js');
@@ -90,7 +90,7 @@ describe('CopyFiles L0 Suite', function () {
9090
done();
9191
});
9292

93-
it('copy files and subtract based on exclude pattern', (done: MochaDone) => {
93+
it('copy files and subtract based on exclude pattern', (done: Mocha.Done) => {
9494
this.timeout(1000);
9595

9696
let testPath = path.join(__dirname, 'L0copySubtractExclude.js');
@@ -121,7 +121,7 @@ describe('CopyFiles L0 Suite', function () {
121121
done();
122122
});
123123

124-
it('fails if Contents not set', (done: MochaDone) => {
124+
it('fails if Contents not set', (done: Mocha.Done) => {
125125
this.timeout(1000);
126126

127127
let testPath = path.join(__dirname, 'L0failsIfContentsNotSet.js');
@@ -133,7 +133,7 @@ describe('CopyFiles L0 Suite', function () {
133133
done();
134134
});
135135

136-
it('fails if SourceFolder not set', (done: MochaDone) => {
136+
it('fails if SourceFolder not set', (done: Mocha.Done) => {
137137
this.timeout(1000);
138138

139139
let testPath = path.join(__dirname, 'L0failsIfSourceFolderNotSet.js');
@@ -145,7 +145,7 @@ describe('CopyFiles L0 Suite', function () {
145145
done();
146146
});
147147

148-
it('fails if TargetFolder not set', (done: MochaDone) => {
148+
it('fails if TargetFolder not set', (done: Mocha.Done) => {
149149
this.timeout(1000);
150150

151151
let testPath = path.join(__dirname, 'L0failsIfTargetFolderNotSet.js');
@@ -157,7 +157,7 @@ describe('CopyFiles L0 Suite', function () {
157157
done();
158158
});
159159

160-
it('fails if SourceFolder not found', (done: MochaDone) => {
160+
it('fails if SourceFolder not found', (done: Mocha.Done) => {
161161
this.timeout(1000);
162162

163163
let testPath = path.join(__dirname, 'L0failsIfSourceFolderNotFound.js');
@@ -169,7 +169,7 @@ describe('CopyFiles L0 Suite', function () {
169169
done();
170170
});
171171

172-
it('fails if target file is a directory', (done: MochaDone) => {
172+
it('fails if target file is a directory', (done: Mocha.Done) => {
173173
this.timeout(1000);
174174

175175
let testPath = path.join(__dirname, 'L0failsIfTargetFileIsDir.js');
@@ -181,7 +181,7 @@ describe('CopyFiles L0 Suite', function () {
181181
done();
182182
});
183183

184-
it('skips if exists', (done: MochaDone) => {
184+
it('skips if exists', (done: Mocha.Done) => {
185185
this.timeout(1000);
186186

187187
let testPath = path.join(__dirname, 'L0skipsIfExists.js');
@@ -206,7 +206,7 @@ describe('CopyFiles L0 Suite', function () {
206206
done();
207207
});
208208

209-
it('overwrites if specified', (done: MochaDone) => {
209+
it('overwrites if specified', (done: Mocha.Done) => {
210210
this.timeout(1000);
211211

212212
let testPath = path.join(__dirname, 'L0overwritesIfSpecified.js');
@@ -231,7 +231,7 @@ describe('CopyFiles L0 Suite', function () {
231231
done();
232232
});
233233

234-
it('preserves timestamp if specified', (done: MochaDone) => {
234+
it('preserves timestamp if specified', (done: Mocha.Done) => {
235235
this.timeout(1000);
236236

237237
let testPath = path.join(__dirname, 'L0preservesTimestampIfSpecified.js');
@@ -259,7 +259,7 @@ describe('CopyFiles L0 Suite', function () {
259259
done();
260260
});
261261

262-
it('cleans if specified', (done: MochaDone) => {
262+
it('cleans if specified', (done: Mocha.Done) => {
263263
this.timeout(1000);
264264

265265
let testPath = path.join(__dirname, 'L0cleansIfSpecified.js');
@@ -290,7 +290,7 @@ describe('CopyFiles L0 Suite', function () {
290290
done();
291291
});
292292

293-
it('cleans if specified and target is file', (done: MochaDone) => {
293+
it('cleans if specified and target is file', (done: Mocha.Done) => {
294294
this.timeout(1000);
295295

296296
let testPath = path.join(__dirname, 'L0cleansIfSpecifiedAndTargetIsFile.js');
@@ -318,7 +318,7 @@ describe('CopyFiles L0 Suite', function () {
318318
done();
319319
});
320320

321-
it('roots patterns', (done: MochaDone) => {
321+
it('roots patterns', (done: Mocha.Done) => {
322322
this.timeout(1000);
323323

324324
let testPath = path.join(__dirname, 'L0rootsPatterns.js');
@@ -341,7 +341,7 @@ describe('CopyFiles L0 Suite', function () {
341341
});
342342

343343
if (process.platform == 'win32') {
344-
it('overwrites readonly', (done: MochaDone) => {
344+
it('overwrites readonly', (done: Mocha.Done) => {
345345
this.timeout(1000);
346346

347347
let testPath = path.join(__dirname, 'L0overwritesReadonly.js');

Tasks/CopyFilesV2/Tests/L0cleansIfSpecified.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,17 +41,14 @@ runner.registerMockExport('stats', (itemPath: string) => {
4141
}
4242
});
4343
let origReaddirSync = fs.readdirSync;
44-
fs.readdirSync = (p: string | Buffer) => {
44+
fs.readdirSync = (p) => {
4545
console.log('HERE path ' + p);
46-
let result: string[];
4746
if (p == path.normalize('/destDir')) {
48-
result = [ 'clean-subDir', 'clean-file.txt' ];
47+
return [ 'clean-subDir', 'clean-file.txt'] as any;
4948
}
5049
else {
51-
result = origReaddirSync(p);
50+
return origReaddirSync(p);
5251
}
53-
54-
return result;
5552
}
5653

5754
// as a precaution, disable fs.chmodSync. it should not be called during this scenario.

Tasks/CopyFilesV2/Tests/L0preservesTimestampIfSpecified.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import fs = require('fs');
22
import mockanswer = require('azure-pipelines-task-lib/mock-answer');
33
import mockrun = require('azure-pipelines-task-lib/mock-run');
44
import path = require('path');
5+
const { promisify } = require('util')
56

67
let taskPath = path.join(__dirname, '..', 'copyfiles.js');
78
let runner: mockrun.TaskMockRunner = new mockrun.TaskMockRunner(taskPath);
@@ -46,9 +47,9 @@ runner.registerMockExport('stats', (itemPath: string) => {
4647
}
4748
});
4849

49-
fs.utimes = function (targetPath, atime, mtime, err) {
50+
fs.utimes = promisify(function (targetPath, atime, mtime, err) {
5051
console.log('Calling fs.utimes on', targetPath);
51-
}
52+
});
5253
runner.registerMock('fs', fs);
5354

5455
runner.run();

0 commit comments

Comments
 (0)