How to use removeFolders method in Playwright Internal

Best JavaScript code snippet using playwright-internal

Run Playwright Internal automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

clean.js

Source: clean.js Github

copy
1const commandLineArgs = require('command-line-args');
2const removeFolders = require("./FileSystem/removeFolders");
3const logger = require("./logger");
4const nodeModulesFolder = "./node_modules";
5const buildOutputFolder = "../wwwroot/App";
6
7const options = commandLineArgs([
8  { name: 'target', alias: 't', type: String, multiple: true }
9]);
10
11const cleanArguments = {
12  targets: options.target || ["build-output"]  // by default, clean build output
13};
14
15const getAction = target => {
16  switch (target) {
17    case "build-output":
18      return removeFolders([buildOutputFolder]);
19    case "node-modules":
20      return removeFolders([nodeModulesFolder]);
21  }
22};
23
24cleanArguments.targets
25  .map(getAction)
26  .reduce(
27    (promise, nextAction) => promise.then(nextAction, logger.logError),
28    Promise.resolve(true)
29  );
30
31
Full Screen

index.js

Source: index.js Github

copy
1const fs = require('fs');
2const path = require('path');
3const rimraf = require('rimraf');
4const rm = require('./rm');
5const packageJson = require('./packageJson');
6
7const root = path.resolve();
8
9function removeFolder(folder) {
10  rimraf.sync(folder);
11}
12
13function removeFile(file) {
14  return new Promise(resolve => {
15    fs.unlink(file, () => {
16      resolve();
17    });
18  });
19}
20
21function writeFile(data, file) {
22  return new Promise(resolve => {
23    fs.writeFileSync(file, data, err => {
24      console.error(err);
25      resolve();
26    });
27  });
28}
29
30async function removeFiles(files) {
31  const promises = [];
32  /* eslint-disable-next-line */
33  for (const file of files) {
34    promises.push(removeFile(file));
35  }
36  await Promise.all(promises);
37}
38
39async function removeFolders(folders) {
40  const promises = [];
41  /* eslint-disable-next-line */
42  for (const folder of folders) {
43    promises.push(removeFolder(folder));
44  }
45  await Promise.all(promises);
46}
47
48async function run(options) {
49  // Update package.json
50  const newPackageJson = packageJson.update(options);
51  writeFile(JSON.stringify(newPackageJson, null, 2), `${root}/package.json`);
52
53  await removeFiles([`${root}/package-lock.json`]);
54  await removeFolders([`${root}/node_modules`]);
55
56  // Remove sentry
57  if (options.sentry) {
58    await rm.removeLines(`${root}/src/main.js`, [2, 3, 8, 9, [13, 21]]);
59  }
60
61  // Remove cypress
62  if (options.cypress) {
63    await removeFiles([
64      `${root}/docker-compose.e2e.yml`,
65      `${root}/cy-open.yml`,
66      `${root}/cypress.json`,
67      `${root}/docker/Dockerfile.e2e`,
68      `${root}/tests/.eslintrc.js`
69    ]);
70    await removeFolders([`${root}/tests/e2e`, `${root}/tests/server`]);
71  }
72
73  // Remove jest
74  if (options.jest) {
75    await removeFiles([`${root}/jest.config.js`, `${root}/jest-coverage-badges.js`]);
76    await removeFolders([`${root}/tests/unit`]);
77  }
78
79  // Remove linter
80  if (options.linter) {
81    await removeFiles([`${root}/.eslintignore`, `${root}/.eslintrc.js`]);
82  }
83
84  // Remove gitlab pages
85  if (options.gitlabPage) {
86    await removeFiles([`${root}/vue.config.js`]);
87  }
88
89  // Remove vue Doc
90  if (options.vueDoc) {
91    await removeFolders([`${root}/docs/components`]);
92  }
93
94  // Remove i18n
95  if (options.multiLanguage) {
96    await removeFolders([`${root}/src/locales`]);
97    if (options.sentry) {
98      await rm.removeLines(`${root}/src/main.js`, [5, 12]);
99    } else {
100      await rm.removeLines(`${root}/src/main.js`, [7, 25]);
101    }
102  }
103
104  // Remove mdb
105  if (options.mdb) {
106    await rm.removeLines(`${root}/public/index.html`, [8]);
107    await rm.removeLines(`${root}/src/assets/scss/index.scss`, [2]);
108  }
109
110  // Remove prettier
111  if (options.prettier) {
112    await removeFiles([`${root}/.prettierrc`]);
113  }
114
115  return true;
116}
117
118module.exports = { run };
119
Full Screen

Accelerate Your Automation Test Cycles With LambdaTest

Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.

Try LambdaTest

Run JavaScript Tests on LambdaTest Cloud Grid

Execute automation tests with Playwright Internal on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.

Test now for Free
LambdaTestX

We use cookies to give you the best experience. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. Learn More in our Cookies policy, Privacy & Terms of service

Allow Cookie
Sarah

I hope you find the best code examples for your project.

If you want to accelerate automated browser testing, try LambdaTest. Your first 100 automation testing minutes are FREE.

Sarah Elson (Product & Growth Lead)