Skip to content

Commit

Permalink
Use Jest for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
anthony-c-martin committed Jan 22, 2024
1 parent 3c6bf87 commit c61225f
Show file tree
Hide file tree
Showing 25 changed files with 7,861 additions and 1,335 deletions.
48 changes: 48 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
module.exports = {
root: true,
parser: "@typescript-eslint/parser",
parserOptions: {
ecmaVersion: 2020,
sourceType: "module",
project: './tsconfig.json',
},
plugins: ["header"],
extends: ["eslint:recommended", "plugin:prettier/recommended"],
ignorePatterns: ["/out/**/*"],
rules: {
"header/header": [
2,
"line",
[
" Copyright (c) Microsoft Corporation.",
" Licensed under the MIT License.",
],
],
},
overrides: [
{
files: ["*.ts"],
extends: [
"plugin:@typescript-eslint/recommended",
"plugin:jest/all",
"plugin:prettier/recommended",
],
rules: {
"jest/no-hooks": "off",
"jest/prefer-expect-assertions": "off",
"jest/expect-expect": [
"error",
{
assertFunctionNames: ["expect*", "invokingBicepCommand"],
},
],
},
},
{
files: ["*.js"],
env: { node: true },
},
],
};
40 changes: 0 additions & 40 deletions .github/workflows/build-release.yaml

This file was deleted.

122 changes: 36 additions & 86 deletions .github/workflows/ci-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,96 +26,46 @@ jobs:

- run: npm ci

- name: Resource group scope test
- name: Run Tests
env:
INPUT_SCOPE: resourcegroup
INPUT_SUBSCRIPTIONID: ${{ secrets.SUBSCRIPTION_ID }}
INPUT_RESOURCEGROUPNAME: E2eTestResourceGroupForArmAction
INPUT_TEMPLATE: https://raw.githubusercontent.com/Azure/azure-quickstart-templates/master/quickstarts/microsoft.web/webapp-basic-linux/azuredeploy.json
INPUT_PARAMETERS: https://raw.githubusercontent.com/Azure/azure-quickstart-templates/master/quickstarts/microsoft.web/webapp-basic-linux/azuredeploy.parameters.json
INPUT_DEPLOYMENTNAME: github-test-rg
INPUT_DEPLOYMENTMODE: Complete
EXPECTED_TO: pass
run: npm test

- name: Resource group scope test - Negative
env:
INPUT_SCOPE: resourcegroup
INPUT_SUBSCRIPTIONID: ${{ secrets.SUBSCRIPTION_ID }}
INPUT_RESOURCEGROUPNAME: E2eTestResourceGroupForArmAction
INPUT_TEMPLATE: ./test/resourceGroup-Negative/template.json
INPUT_PARAMETERS: ./test/resourceGroup-Negative/parameters.json
INPUT_REGION: eastasia
INPUT_DEPLOYMENTNAME: github-test-rg
INPUT_DEPLOYMENTMODE: Complete
EXPECTED_TO: fail
run: npm test

# - name: Management group scope test
# env:
# INPUT_SCOPE: managementgroup
# INPUT_MANAGEMENTGROUPID: E2eTestGroupForArmAction
# INPUT_REGION: WestUS
# INPUT_TEMPLATE: ./test/template.json
# INPUT_PARAMETERS: ./test/parameters.json
# INPUT_DEPLOYMENTNAME: github-test-mg
# EXPECTED_TO: pass
# run: npm test

- name: Subscription scope test
env:
INPUT_SCOPE: subscription
INPUT_SUBSCRIPTIONID: ${{ secrets.SUBSCRIPTION_ID }}
INPUT_REGION: centralus
INPUT_TEMPLATE: https://raw.githubusercontent.com/Azure/azure-docs-json-samples/master/azure-resource-manager/emptyrg.json
INPUT_PARAMETERS: rgName=demoResourceGroup rgLocation=centralus
INPUT_DEPLOYMENTNAME: github-test-subs
EXPECTED_TO: pass
run: npm test

- name: Subscription scope test - Negative
env:
INPUT_SCOPE: subscription
INPUT_SUBSCRIPTIONID: ${{ secrets.SUBSCRIPTION_ID }}
INPUT_REGION: centralus
INPUT_TEMPLATE: ./test/subscription-Negative/template.json
INPUT_PARAMETERS: rgName=demoResourceGroup rgLocation=centralus
INPUT_DEPLOYMENTNAME: github-test-subs
EXPECTED_TO: fail
SUBSCRIPTION_ID: ${{ secrets.SUBSCRIPTION_ID }}
run: npm test

# - name: Tenant scope test
# env:
# INPUT_SCOPE: tenant
# INPUT_SUBSCRIPTIONID: ${{ secrets.SUBSCRIPTION_ID }}
# INPUT_REGION: centralus
# INPUT_TEMPLATE: ./test/tenant/template.json
# INPUT_PARAMETERS: ./test/tenant/parameters.json
# INPUT_DEPLOYMENTNAME: github-test-ten
# EXPECTED_TO: pass
# run: ts-node test/main.tests.ts

# - name: Tenant scope test - Negative
# env:
# INPUT_SCOPE: tenant
# INPUT_SUBSCRIPTIONID: ${{ secrets.SUBSCRIPTION_ID }}
# INPUT_REGION: centralus
# INPUT_TEMPLATE: ./test/tenant/negative/template.json
# INPUT_PARAMETERS: ./test/tenant/negative/parameters.json
# INPUT_DEPLOYMENTNAME: github-test-ten
# EXPECTED_TO: fail
# run: ts-node test/main.tests.ts

- name: Validate mode test
run-tests-edge:
name: Run Tests (Edge)
runs-on: ubuntu-latest
steps:
- name: Check out source code
uses: actions/checkout@v1

- name: Installing Az CLI Edge build
run: |
cd ../..
CWD="$(pwd)"
python3 -m venv oidc-venv
. oidc-venv/bin/activate
echo "***********activated virual environment**********"
python3 -m pip install --upgrade pip
echo "***************started installing cli edge build******************"
pip3 install -q --upgrade --pre azure-cli --extra-index-url https://azurecliprod.blob.core.windows.net/edge --no-cache-dir --upgrade-strategy=eager
echo "***************installed cli Edge build*******************"
echo "$CWD/oidc-venv/bin" >> $GITHUB_PATH
az --version
- uses: azure/login@v1
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}

- name: Setup Node.js
uses: actions/setup-node@v1
with:
node-version: "20.x"

- run: npm ci

- name: Run Tests
env:
INPUT_SCOPE: resourcegroup
INPUT_SUBSCRIPTIONID: ${{ secrets.SUBSCRIPTION_ID }}
INPUT_RESOURCEGROUPNAME: E2eTestResourceGroupForArmAction
INPUT_TEMPLATE: https://raw.githubusercontent.com/Azure/azure-quickstart-templates/master/quickstarts/microsoft.web/webapp-basic-linux/azuredeploy.json
INPUT_PARAMETERS: https://raw.githubusercontent.com/Azure/azure-quickstart-templates/master/quickstarts/microsoft.web/webapp-basic-linux/azuredeploy.parameters.json
INPUT_DEPLOYMENTNAME: github-test-rg
INPUT_DEPLOYMENTMODE: Validate
EXPECTED_TO: pass
SUBSCRIPTION_ID: ${{ secrets.SUBSCRIPTION_ID }}
run: npm test

execute-action:
Expand Down
122 changes: 0 additions & 122 deletions .github/workflows/edge-build-ci-workflow.yml

This file was deleted.

2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"skipFiles": [
"<node_internals>/**"
],
"program": "${workspaceFolder}/src/entrypoint.ts",
"program": "${workspaceFolder}/src/run.ts",
"outFiles": [
"${workspaceFolder}/_build/*.js"
],
Expand Down
4 changes: 2 additions & 2 deletions HowToDebug.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ Open PowerShell, go to the directory where the repo is stored (.../arm-deploy/)
**1.npm install** \
npm install downloads dependencies defined in a package. json file and generates a node_modules folder with the installed modules. \
**2.npm install -g @vercel/ncc** \
**3.ncc build src/entrypoint.ts -s -o _build** \
**3.ncc build src/run.ts -s -o _build** \
ncc is a simple CLI for compiling a Node.js module into a single file, together with all its dependencies, gcc-style. \
**4. az login** \
This will open the browser, where you can do the Azure login which gives you proper access required for the action.

Open the arm-deploy repository in VSCode, attach debugging points at required places _(flow begins from entrypoint.ts)_ and press F5. The debugger gets attached.
Open the arm-deploy repository in VSCode, attach debugging points at required places _(flow begins from run.ts)_ and press F5. The debugger gets attached.

Also, for various input values required while testing, you can specify those as environment variables in launch.json that gets created. \
_Happy debugging!_
Loading

0 comments on commit c61225f

Please sign in to comment.