Skip to content

Commit

Permalink
test: improve NUT test with E2E tests (#659)
Browse files Browse the repository at this point in the history
  • Loading branch information
scolladon authored Jul 25, 2023
1 parent 0f8a869 commit 63d6917
Show file tree
Hide file tree
Showing 6 changed files with 147 additions and 105 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/on-main-push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ jobs:
sfdx plugins:link .
sfdx plugins
- name: Checkout e2e sources
- name: Checkout e2e test subject
uses: actions/checkout@v3
with:
ref: 'e2e/head'
Expand Down
20 changes: 7 additions & 13 deletions .github/workflows/on-pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -137,23 +137,13 @@ jobs:
steps:
- name: Checkout sources
uses: actions/checkout@v3
with:
path: ./plugin

- name: Checkout sources
uses: actions/checkout@v3
with:
ref: 'e2e/head'
fetch-depth: 0
path: ./e2e

- name: Setup node
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node }}

- name: Get yarn cache directory path
working-directory: ./plugin
id: yarn-cache-dir-path
run: echo "yarn-cache=$(yarn config get cacheFolder)" >> "$GITHUB_OUTPUT"
shell: bash
Expand All @@ -164,23 +154,27 @@ jobs:
key: ${{ runner.os }}-${{ matrix.node }}-yarn-${{ hashFiles('**/yarn.lock') }}

- name: Install dependencies
working-directory: ./plugin
run: yarn install --immutable --check-cache

- name: Build plugin
working-directory: ./plugin
run: yarn pack

- name: Install sfdx-cli
run: npm install -g sfdx-cli

- name: Install plugin
working-directory: ./plugin
run: |
yarn set version classic
sfdx plugins:link .
sfdx plugins
- name: Checkout e2e test subject
uses: actions/checkout@v3
with:
ref: 'e2e/head'
fetch-depth: 0
path: ./e2e

- name: E2E Tests
working-directory: ./e2e
run: |
Expand Down
7 changes: 7 additions & 0 deletions .github/workflows/reusable-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ jobs:
token: ${{ secrets.CODECOV_TOKEN }}
continue-on-error: true

- name: Checkout e2e sources
uses: actions/checkout@v3
with:
ref: 'e2e/head'
fetch-depth: 0
path: ./e2e

- name: Functional test
run: yarn test:nut

Expand Down
34 changes: 34 additions & 0 deletions __tests__/functional/delta.nut.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
'use strict'
const { execCmd } = require('@salesforce/cli-plugins-testkit')
const { expect } = require('@salesforce/command/lib/test')
const readline = require('readline')
const fs = require('fs')

describe('sgd:source:delta NUTS', () => {
it('run help', () => {
Expand Down Expand Up @@ -41,4 +43,36 @@ describe('sgd:source:delta NUTS', () => {
expect(result).to.include('"error": null')
expect(result).to.include('"success": true')
})

it('run `e2e` tests', async () => {
// Act
const result = execCmd(
'sgd:source:delta --from "origin/e2e/base" --to "origin/e2e/head" --output e2e/expected --generate-delta --repo e2e --ignore e2e/.sgdignore',
{
ensureExitCode: 0,
}
).shellOutput

// Assert
const packageLineCount = await getFileLineNumber(
'e2e/expected/package/package.xml'
)
expect(packageLineCount).to.equal(194)
expect(result).to.include('"error": null')
expect(result).to.include('"success": true')
})
})

const getFileLineNumber = async path => {
let linesCount = 0
const rl = readline.createInterface({
input: fs.createReadStream(path),
output: process.stdout,
terminal: false,
})
// eslint-disable-next-line no-unused-vars
for await (const _ of rl) {
++linesCount
}
return linesCount
}
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,10 @@
"@salesforce/ts-sinon": "^1.4.12",
"@stryker-mutator/core": "^7.1.1",
"@stryker-mutator/jest-runner": "^7.1.1",
"@swc/core": "^1.3.70",
"@swc/core": "^1.3.71",
"@types/mocha": "^10.0.1",
"@types/node": "^20.4.4",
"@typescript-eslint/parser": "^6.1.0",
"@typescript-eslint/parser": "^6.2.0",
"benchmark": "^2.1.4",
"chai": "^4.3.7",
"depcheck": "^1.4.3",
Expand Down
Loading

0 comments on commit 63d6917

Please sign in to comment.