Skip to content

Commit

Permalink
further refactoring & updates
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxKless committed Nov 25, 2022
1 parent be2bbeb commit b07e2b2
Show file tree
Hide file tree
Showing 25 changed files with 221 additions and 518 deletions.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
68 changes: 68 additions & 0 deletions apps/vscode-e2e/services/testworkspace-installation.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import { exec } from 'child_process';
import {
existsSync,
rmSync,
readdirSync,
mkdirSync,
lstatSync,
copyFileSync,
} from 'fs';
import { basename, dirname, join } from 'path';
import { promisify } from 'util';
import { SevereServiceError } from 'webdriverio';
import { getTestWorkspacePath } from '../specs/utils';

export class TestworkspaceInstallationService {
async onPrepare() {
const testWorkspacePath = getTestWorkspacePath();
if (existsSync(testWorkspacePath)) {
rmSync(testWorkspacePath, { recursive: true, force: true });
}

// copy testworkspaces and remove after running the tests
copyFolderRecursiveSync(`./testworkspaces`, dirname(testWorkspacePath));
const testWorkspaces = readdirSync(testWorkspacePath, {
withFileTypes: true,
}).filter((dirent) => dirent.isDirectory());

process.on('exit', () => {
rmSync(testWorkspacePath, { recursive: true, force: true });
});

console.log('installing testworkspace dependencies....');
console.time('done in');
await Promise.all(
testWorkspaces.map(async (tws) => {
await promisify(exec)('npm ci', {
cwd: join(testWorkspacePath, tws.name),
}).catch((e) => {
throw new SevereServiceError();
// `Failed to install dependencies for ${tws.name}: \n ${e}`
});
})
);

console.timeLog('done in');
}
}

function copyFolderRecursiveSync(source: string, target: string) {
// Check if folder needs to be created or integrated
const targetFolder = join(target, basename(source));
if (!existsSync(targetFolder)) {
mkdirSync(targetFolder);
}

// Copy everything but ignore node_modules
if (lstatSync(source).isDirectory() && !source.includes('node_modules')) {
const files = readdirSync(source);
files.forEach(function (file) {
const curSource = join(source, file);
if (lstatSync(curSource).isDirectory()) {
copyFolderRecursiveSync(curSource, targetFolder);
} else {
copyFileSync(curSource, join(targetFolder, file));
}
});
}
}
Loading

0 comments on commit b07e2b2

Please sign in to comment.