From 70c4e8a6d75dee851dda81325705a36a1fdd6caf Mon Sep 17 00:00:00 2001 From: Christian Bromann Date: Thu, 8 Aug 2024 07:37:22 -0700 Subject: [PATCH] chore(deps): install Jest dependencies via TypeScript and Node (#5928) --- CONTRIBUTING.md | 2 +- package.json | 2 +- src/testing/jest/install-dependencies.mts | 39 +++++++++++++++++++++++ src/testing/jest/install-dependencies.sh | 34 -------------------- 4 files changed, 41 insertions(+), 36 deletions(-) create mode 100755 src/testing/jest/install-dependencies.mts delete mode 100755 src/testing/jest/install-dependencies.sh diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index a73252e8aaf..7a2e9e565cf 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -51,7 +51,7 @@ Please see our [Contributor Code of Conduct](https://github.com/ionic-team/stenc 1. There's no need to install a specific version of npm or Node right now, it shall be done automatically for you in the next step 5. Run `npm ci` -6. Run `npm install.jest` to install dependencies for Stencil's testing submodule +6. Run `npm run install.jest` to install dependencies for Stencil's testing submodule ### Updates diff --git a/package.json b/package.json index ea0944682ca..638cff9be16 100644 --- a/package.json +++ b/package.json @@ -100,7 +100,7 @@ "clean.screenshots": "rm -rf test/end-to-end/screenshot/builds test/end-to-end/screenshot/images", "clean:scripts": "rm -rf scripts/build", "lint": "eslint 'bin/*' 'scripts/*.ts' 'scripts/**/*.ts' 'src/*.ts' 'src/**/*.ts' 'src/**/*.tsx' 'test/wdio/**/*.tsx'", - "install.jest": "bash ./src/testing/jest/install-dependencies.sh", + "install.jest": "npx tsx ./src/testing/jest/install-dependencies.mts", "prettier": "npm run prettier.base -- --write", "prettier.base": "prettier --cache \"./({bin,scripts,src,test}/**/*.{ts,tsx,js,jsx})|bin/stencil|.github/(**/)?*.(yml|yaml)|*.js\"", "prettier.dry-run": "npm run prettier.base -- --list-different", diff --git a/src/testing/jest/install-dependencies.mts b/src/testing/jest/install-dependencies.mts new file mode 100755 index 00000000000..9cfaf9c4f80 --- /dev/null +++ b/src/testing/jest/install-dependencies.mts @@ -0,0 +1,39 @@ +import { exec } from 'node:child_process'; +import fss from 'node:fs'; +import fs from 'node:fs/promises'; +import path from 'node:path' +import url from 'node:url' + +const __dirname = url.fileURLToPath(new URL('.', import.meta.url)); +let found = false; + +const jestAdapters = (await fs.readdir(__dirname)) + .filter((file) => file.startsWith('jest-')) + .filter((file) => fss.statSync(path.join(__dirname, file)).isDirectory()); + +/** + * Loop through directories start with 'jest-', e.g. `jest-27-and-under`, `jest-28`, etc. + */ +for (const dir of jestAdapters) { + found = true; + + const jestDir = path.join(__dirname, dir); + console.log(`→ Installing dependencies in ${jestDir}...`); + await new Promise((resolve, reject) => { + exec('npm ci', { cwd: jestDir }, (err) => { + if (err) { + reject(err); + } + resolve(); + }); + }); + console.log('Done 🎉'); +} + +/** + * If no directories were found and processed, print an error and exit + */ +if (!found) { + console.error('Error: No jest directories were found'); + process.exit(1); +} diff --git a/src/testing/jest/install-dependencies.sh b/src/testing/jest/install-dependencies.sh deleted file mode 100755 index c69add8da56..00000000000 --- a/src/testing/jest/install-dependencies.sh +++ /dev/null @@ -1,34 +0,0 @@ -#!/bin/bash - -set -e -u -o pipefail - -# Get the directory where this script is located - doing so will allow us to run the script from anywhere in the -# project. Since we retrieve the directory this script lives in via a subshell, we'll need to `cd` to in explicitly in -# a separate command. -SCRIPT_DIR=$(cd "$(dirname "$0")" && pwd) -cd "$SCRIPT_DIR" - -# Flag to check if any jest-[SOME_NUMBER] directories were found and processed -found=false - -# Loop through directories start with 'jest-', e.g. `jest-27-and-under`, `jest-28`, etc. -for dir in jest-*; do - if [[ -d "$dir" ]]; then - found=true - - cd "$dir" - echo "Installing dependencies in $dir" - npm ci - # print a newline to separate sequential installs - echo "" - - # go back to where we started - cd - - fi -done - -# If no directories were found and processed, print an error and exit -if [[ $found == false ]]; then - echo "Error: No jest directories were found" - exit 1 -fi