Skip to content

Commit

Permalink
[CopyFilesV2] Migrated to Node10 (#14710)
Browse files Browse the repository at this point in the history
* [CopyFilesV2] Migrated to Node10

* Addressed code review points

Co-authored-by: Anatoly Bolshakov <anatoly.bolshakov@akvelon.com>
Co-authored-by: Nikita Ezzhev <v-niezz@microsoft.com>
  • Loading branch information
3 people authored Apr 15, 2021
1 parent 392108a commit e8abe8b
Show file tree
Hide file tree
Showing 15 changed files with 336 additions and 4,018 deletions.
30 changes: 15 additions & 15 deletions Tasks/CopyFilesV2/Tests/L0.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ describe('CopyFiles L0 Suite', function () {

after(() => { });

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

let testPath = path.join(__dirname, 'L0copyAllFiles.js');
Expand Down Expand Up @@ -50,7 +50,7 @@ describe('CopyFiles L0 Suite', function () {
done();
});

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

let testPath = path.join(__dirname, 'L0copyAllFilesWithBracketsInSrcPath.js');
Expand Down Expand Up @@ -90,7 +90,7 @@ describe('CopyFiles L0 Suite', function () {
done();
});

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

let testPath = path.join(__dirname, 'L0copySubtractExclude.js');
Expand Down Expand Up @@ -121,7 +121,7 @@ describe('CopyFiles L0 Suite', function () {
done();
});

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

let testPath = path.join(__dirname, 'L0preservesTimestampIfSpecified.js');
Expand Down Expand Up @@ -259,7 +259,7 @@ describe('CopyFiles L0 Suite', function () {
done();
});

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

let testPath = path.join(__dirname, 'L0cleansIfSpecified.js');
Expand Down Expand Up @@ -290,7 +290,7 @@ describe('CopyFiles L0 Suite', function () {
done();
});

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

let testPath = path.join(__dirname, 'L0cleansIfSpecifiedAndTargetIsFile.js');
Expand Down Expand Up @@ -318,7 +318,7 @@ describe('CopyFiles L0 Suite', function () {
done();
});

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

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

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

let testPath = path.join(__dirname, 'L0overwritesReadonly.js');
Expand Down
9 changes: 3 additions & 6 deletions Tasks/CopyFilesV2/Tests/L0cleansIfSpecified.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,14 @@ runner.registerMockExport('stats', (itemPath: string) => {
}
});
let origReaddirSync = fs.readdirSync;
fs.readdirSync = (p: string | Buffer) => {
fs.readdirSync = (p) => {
console.log('HERE path ' + p);
let result: string[];
if (p == path.normalize('/destDir')) {
result = [ 'clean-subDir', 'clean-file.txt' ];
return [ 'clean-subDir', 'clean-file.txt'] as any;
}
else {
result = origReaddirSync(p);
return origReaddirSync(p);
}

return result;
}

// as a precaution, disable fs.chmodSync. it should not be called during this scenario.
Expand Down
5 changes: 3 additions & 2 deletions Tasks/CopyFilesV2/Tests/L0preservesTimestampIfSpecified.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import fs = require('fs');
import mockanswer = require('azure-pipelines-task-lib/mock-answer');
import mockrun = require('azure-pipelines-task-lib/mock-run');
import path = require('path');
const { promisify } = require('util')

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

fs.utimes = function (targetPath, atime, mtime, err) {
fs.utimes = promisify(function (targetPath, atime, mtime, err) {
console.log('Calling fs.utimes on', targetPath);
}
});
runner.registerMock('fs', fs);

runner.run();
Loading

0 comments on commit e8abe8b

Please sign in to comment.