Skip to content

Commit

Permalink
Upgrade CopyFilesV2 to NodeJS 16 (#16899)
Browse files Browse the repository at this point in the history
* Task and tests migrated to Node16

* Rolled back minimumAgentVersion

* Rolled back minimumAgentVersion in task.loc.json

* Rolled back libraries version
  • Loading branch information
Roman-Shchukin authored Sep 28, 2022
1 parent f907d83 commit 3928216
Show file tree
Hide file tree
Showing 19 changed files with 627 additions and 568 deletions.
6 changes: 3 additions & 3 deletions Tasks/CopyFilesV2/Tests/L0.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 Down Expand Up @@ -372,7 +372,7 @@ describe('CopyFiles L0 Suite', function () {
done();
});

it('ignores errors during target folder creation if ignoreMakeDirErrors is true', (done: MochaDone) => {
it('ignores errors during target folder creation if ignoreMakeDirErrors is true', (done: Mocha.Done) => {
let testPath = path.join(__dirname, 'L0IgnoresMakeDirError.js');
let runner: mocktest.MockTestRunner = new mocktest.MockTestRunner(testPath);
runner.run();
Expand All @@ -390,7 +390,7 @@ describe('CopyFiles L0 Suite', function () {
done();
});

it('fails if there are errors during target folder creation if ignoreMakeDirErrors is false', (done: MochaDone) => {
it('fails if there are errors during target folder creation if ignoreMakeDirErrors is false', (done: Mocha.Done) => {
let testPath = path.join(__dirname, 'L0FailsIfThereIsMkdirError.js');
let runner: mocktest.MockTestRunner = new mocktest.MockTestRunner(testPath);
runner.run();
Expand Down
60 changes: 31 additions & 29 deletions Tasks/CopyFilesV2/Tests/L0FailsIfThereIsMkdirError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,41 +24,43 @@ answers.find[path.normalize('/srcDir')] = [
];
runner.setAnswers(answers);

fs.existsSync = (itemPath: string) => {
switch (itemPath) {
case path.normalize('/srcDir/someOtherDir'):
case path.normalize('/srcDir/someOtherDir/file1.file'):
case path.normalize('/srcDir/someOtherDir/file2.file'):
return true;
default:
return false;
}
}

fs.statSync = (itemPath: string) => {
const itemStats: fs.Stats = new fs.Stats();
switch (itemPath) {
case path.normalize('/srcDir/someOtherDir'):
itemStats.isDirectory = () => true;
break;
case path.normalize('/srcDir/someOtherDir/file1.file'):
case path.normalize('/srcDir/someOtherDir/file2.file'):
itemStats.isDirectory = () => false;
break;
default:
throw { code: 'ENOENT' };
}
return itemStats;
}
const fsClone = Object.assign({}, fs);
Object.assign(fsClone, {
existsSync(itemPath: string): boolean {
switch (itemPath) {
case path.normalize('/srcDir/someOtherDir'):
case path.normalize('/srcDir/someOtherDir/file1.file'):
case path.normalize('/srcDir/someOtherDir/file2.file'):
return true;
default:
return false;
}
},
statSync(itemPath: string): fs.Stats {
const itemStats: fs.Stats = new fs.Stats();
switch (itemPath) {
case path.normalize('/srcDir/someOtherDir'):
itemStats.isDirectory = () => true;
break;
case path.normalize('/srcDir/someOtherDir/file1.file'):
case path.normalize('/srcDir/someOtherDir/file2.file'):
itemStats.isDirectory = () => false;
break;
default:
throw { code: 'ENOENT' };
}
return itemStats;
},
// as a precaution, disable fs.chmodSync. it should not be called during this scenario.
chmodSync(p: fs.PathLike, mode: fs.Mode): void {}
});

runner.registerMockExport('mkdirP', (p: string) => {
console.log(`mkdirP: ${p}`);

throw "Error during creation of target folder."
});

// as a precaution, disable fs.chmodSync. it should not be called during this scenario.
fs.chmodSync = null;
runner.registerMock('fs', fs);
runner.registerMock('fs', fsClone);

runner.run();
60 changes: 31 additions & 29 deletions Tasks/CopyFilesV2/Tests/L0IgnoresMakeDirError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,41 +24,43 @@ answers.find[path.normalize('/srcDir')] = [
];
runner.setAnswers(answers);

fs.existsSync = (itemPath: string) => {
switch (itemPath) {
case path.normalize('/srcDir/someOtherDir'):
case path.normalize('/srcDir/someOtherDir/file1.file'):
case path.normalize('/srcDir/someOtherDir/file2.file'):
return true;
default:
return false;
}
}

fs.statSync = (itemPath: string) => {
const itemStats: fs.Stats = new fs.Stats();
switch (itemPath) {
case path.normalize('/srcDir/someOtherDir'):
itemStats.isDirectory = () => true;
break;
case path.normalize('/srcDir/someOtherDir/file1.file'):
case path.normalize('/srcDir/someOtherDir/file2.file'):
itemStats.isDirectory = () => false;
break;
default:
throw { code: 'ENOENT' };
}
return itemStats;
}
const fsClone = Object.assign({}, fs);
Object.assign(fsClone, {
existsSync(itemPath: string): boolean {
switch (itemPath) {
case path.normalize('/srcDir/someOtherDir'):
case path.normalize('/srcDir/someOtherDir/file1.file'):
case path.normalize('/srcDir/someOtherDir/file2.file'):
return true;
default:
return false;
}
},
statSync(itemPath: string): fs.Stats {
const itemStats: fs.Stats = new fs.Stats();
switch (itemPath) {
case path.normalize('/srcDir/someOtherDir'):
itemStats.isDirectory = () => true;
break;
case path.normalize('/srcDir/someOtherDir/file1.file'):
case path.normalize('/srcDir/someOtherDir/file2.file'):
itemStats.isDirectory = () => false;
break;
default:
throw { code: 'ENOENT' };
}
return itemStats;
},
// as a precaution, disable fs.chmodSync. it should not be called during this scenario.
chmodSync(p: fs.PathLike, mode: fs.Mode): void {}
});

runner.registerMockExport('mkdirP', (p: string) => {
console.log(`mkdirP: ${p}`);

throw "Error during creation of target folder."
});

// as a precaution, disable fs.chmodSync. it should not be called during this scenario.
fs.chmodSync = null;
runner.registerMock('fs', fs);
runner.registerMock('fs', fsClone);

runner.run();
93 changes: 47 additions & 46 deletions Tasks/CopyFilesV2/Tests/L0cleansIfSpecified.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,53 +26,54 @@ answers.rmRF[path.join(path.normalize('/destDir/clean-subDir'))] = { success: tr
answers.rmRF[path.join(path.normalize('/destDir/clean-file.txt'))] = { success: true };
runner.setAnswers(answers);

fs.existsSync = (itemPath: string) => {
switch (itemPath) {
case path.normalize('/destDir'):
case path.normalize('/srcDir'):
case path.normalize('/srcDir/someOtherDir'):
case path.normalize('/srcDir/someOtherDir/file1.file'):
case path.normalize('/srcDir/someOtherDir/file2.file'):
return true;
default:
return false;
}
}

fs.statSync = (itemPath: string) => {
const itemStats: fs.Stats = new fs.Stats();
switch (itemPath) {
case path.normalize('/destDir'):
case path.normalize('/srcDir'):
case path.normalize('/srcDir/someOtherDir'):
itemStats.isDirectory = () => true;
break;
case path.normalize('/srcDir/someOtherDir/file1.file'):
case path.normalize('/srcDir/someOtherDir/file2.file'):
itemStats.isDirectory = () => false;
break;
default:
throw { code: 'ENOENT' };
}
return itemStats;
}

let origReaddirSync = fs.readdirSync;
fs.readdirSync = (p: fs.PathLike, o?: any): any => {
console.log('HERE path ' + p);
let result: string[];
if (p == path.normalize('/destDir')) {
result = [ 'clean-subDir', 'clean-file.txt' ];
}
else {
result = origReaddirSync(p);
}

return result;
}
const fsClone = Object.assign({}, fs);
Object.assign(fsClone, {
existsSync(itemPath: string): boolean {
switch (itemPath) {
case path.normalize('/destDir'):
case path.normalize('/srcDir'):
case path.normalize('/srcDir/someOtherDir'):
case path.normalize('/srcDir/someOtherDir/file1.file'):
case path.normalize('/srcDir/someOtherDir/file2.file'):
return true;
default:
return false;
}
},
statSync(itemPath: string): fs.Stats {
const itemStats: fs.Stats = new fs.Stats();
switch (itemPath) {
case path.normalize('/destDir'):
case path.normalize('/srcDir'):
case path.normalize('/srcDir/someOtherDir'):
itemStats.isDirectory = () => true;
break;
case path.normalize('/srcDir/someOtherDir/file1.file'):
case path.normalize('/srcDir/someOtherDir/file2.file'):
itemStats.isDirectory = () => false;
break;
default:
throw { code: 'ENOENT' };
}
return itemStats;
},
readdirSync(p: fs.PathLike, o?: any): string[] {
console.log('HERE path ' + p);
let result: string[];
if (p == path.normalize('/destDir')) {
result = [ 'clean-subDir', 'clean-file.txt' ];
}
else {
result = origReaddirSync(p);
}

return result;
},
// as a precaution, disable fs.chmodSync. it should not be called during this scenario.
chmodSync(p: fs.PathLike, mode: fs.Mode): void {}
});

// as a precaution, disable fs.chmodSync. it should not be called during this scenario.
fs.chmodSync = null;
runner.registerMock('fs', fs);
runner.registerMock('fs', fsClone);

runner.run();
75 changes: 38 additions & 37 deletions Tasks/CopyFilesV2/Tests/L0cleansIfSpecifiedAndDestDoesntExist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,44 +26,45 @@ answers.rmRF[path.join(path.normalize('/destDir/clean-subDir'))] = { success: tr
answers.rmRF[path.join(path.normalize('/destDir/clean-file.txt'))] = { success: true };
runner.setAnswers(answers);

fs.existsSync = (itemPath: string) => {
switch (itemPath) {
case path.normalize('/srcDir'):
case path.normalize('/srcDir/someOtherDir'):
case path.normalize('/srcDir/someOtherDir/file1.file'):
case path.normalize('/srcDir/someOtherDir/file2.file'):
return true;
default:
return false;
}
}

fs.statSync = (itemPath: string) => {
const itemStats: fs.Stats = new fs.Stats();
switch (itemPath) {
case path.normalize('/srcDir'):
case path.normalize('/srcDir/someOtherDir'):
itemStats.isDirectory = () => true;
break;
case path.normalize('/srcDir/someOtherDir/file1.file'):
case path.normalize('/srcDir/someOtherDir/file2.file'):
itemStats.isDirectory = () => false;
break;
default:
throw { code: 'ENOENT' };
}
return itemStats;
}

let origReaddirSync = fs.readdirSync;
fs.readdirSync = (p: fs.PathLike, o?: any): any => {
console.log('HERE path ' + p);
let result = origReaddirSync(p);
return result;
}
const fsClone = Object.assign({}, fs);
Object.assign(fsClone, {
existsSync(itemPath: string): boolean {
switch (itemPath) {
case path.normalize('/srcDir'):
case path.normalize('/srcDir/someOtherDir'):
case path.normalize('/srcDir/someOtherDir/file1.file'):
case path.normalize('/srcDir/someOtherDir/file2.file'):
return true;
default:
return false;
}
},
statSync(itemPath: string): fs.Stats {
const itemStats: fs.Stats = new fs.Stats();
switch (itemPath) {
case path.normalize('/srcDir'):
case path.normalize('/srcDir/someOtherDir'):
itemStats.isDirectory = () => true;
break;
case path.normalize('/srcDir/someOtherDir/file1.file'):
case path.normalize('/srcDir/someOtherDir/file2.file'):
itemStats.isDirectory = () => false;
break;
default:
throw { code: 'ENOENT' };
}
return itemStats;
},
readdirSync(p: fs.PathLike, o?: any): any {
console.log('HERE path ' + p);
let result = origReaddirSync(p);
return result;
},
// as a precaution, disable fs.chmodSync. it should not be called during this scenario.
chmodSync(p: fs.PathLike, mode: fs.Mode): void {}
});

// as a precaution, disable fs.chmodSync. it should not be called during this scenario.
fs.chmodSync = null;
runner.registerMock('fs', fs);
runner.registerMock('fs', fsClone);

runner.run();
Loading

0 comments on commit 3928216

Please sign in to comment.