Skip to content

Commit

Permalink
test: convert functional test into NUT tests (#543)
Browse files Browse the repository at this point in the history
  • Loading branch information
scolladon authored Mar 30, 2023
1 parent 34259ac commit f2d132d
Show file tree
Hide file tree
Showing 16 changed files with 643 additions and 90 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/reusable-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,13 @@ jobs:
run: yarn pack

- name: Unit test
run: yarn test:coverage --runInBand
run: yarn test:unit:coverage --runInBand

- name: Upload coverage
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
continue-on-error: true

- name: Functional test
run: yarn test:nut
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,7 @@
/lib
*-debug.log
*-error.log
sfdx-git-delta-*.tgz
sfdx-git-delta-*.tgz
/.nyc_output
stderr*.txt
stdout*.txt
3 changes: 2 additions & 1 deletion .husky/pre-push
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

yarn lint
yarn pack
yarn test:coverage
yarn test:unit:coverage
yarn test:nut
yarn analysis force-app
yarn outdated || true
7 changes: 7 additions & 0 deletions .mocharc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"require": "ts-node/register,source-map-support/register",
"watch-extensions": "ts",
"recursive": true,
"reporter": "spec",
"timeout": 5000
}
5 changes: 5 additions & 0 deletions .nycrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"nyc": {
"extends": "@salesforce/dev-config/nyc"
}
}
16 changes: 13 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,28 @@ When developing, use [jest](https://jestjs.io/en/) unit testing to provide test

```bash
# just run test
yarn test
yarn test:unit

# run test with coverage details
yarn test:coverage
yarn test:unit:coverage
```

To execute a particular test, use the following command:

```bash
yarn test -- <path_to_test>
yarn test:unit -- <path_to_test>

```

### NUT Testing sgd

When developing, use mocha testing to provide NUT functional test. To run the mocha tests use the following command from the root directory:

```bash
# run test
yarn test:nut
```

## Editor Configurations

Configure your editor to use our lint and code style rules.
Expand Down
16 changes: 0 additions & 16 deletions __tests__/cli.test.js

This file was deleted.

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

describe('sgd:source:delta NUTS', () => {
it('run help', () => {
const result = execCmd('sgd:source:delta --help', {
ensureExitCode: 0,
}).shellOutput
expect(result).to.include('sgd:source:delta')
})
})
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
'use strict'
const fs = require('fs')
const child_process = require('child_process')
const app = require('../src/main')
const { COMMIT_REF_TYPE, GIT_FOLDER } = require('../src/utils/gitConstants')
const app = require('../../src/main')
const { COMMIT_REF_TYPE, GIT_FOLDER } = require('../../src/utils/gitConstants')
const { outputFile } = require('fs-extra')
jest.mock('fs')
jest.mock('fs-extra')
Expand Down
File renamed without changes.
24 changes: 24 additions & 0 deletions bin/dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/usr/bin/env node

const oclif = require('@oclif/core')

const path = require('path')
const project = path.join(__dirname, '..', 'tsconfig.json')

// In dev mode -> use ts-node and dev plugins
process.env.NODE_ENV = 'development'

// Enable SWC for faster typescript compiling
require('ts-node').register({ project, swc: true })

// In dev mode, always show stack traces
global.oclif = global.oclif || {}

// In dev mode, always show stack traces
global.oclif.debug = true

// Start the CLI
oclif
.run()
.then(require('@oclif/core/flush'))
.catch(require('@oclif/core/handle'))
3 changes: 3 additions & 0 deletions bin/dev.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@echo off
set NODE_ENV=development
node "%~dp0\dev" %*
5 changes: 4 additions & 1 deletion bin/run
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#!/usr/bin/env node

require('@oclif/command').run().catch(require('@oclif/errors/handle'))
require('@oclif/core')
.run()
.then(require('@oclif/core/flush'))
.catch(require('@oclif/core/handle'))
5 changes: 1 addition & 4 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,7 @@ module.exports = {
// testLocationInResults: false,

// The glob patterns Jest uses to detect test files
// testMatch: [
// "**/__tests__/**/*.[jt]s?(x)",
// "**/?(*.)+(spec|test).[tj]s?(x)"
// ],
testMatch: ['**/__tests__/**/*.test.js'],

// An array of regexp pattern strings that are matched against all test paths, matched tests are skipped
testPathIgnorePatterns: [
Expand Down
31 changes: 21 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,22 +45,26 @@
"homepage": "https://github.com/scolladon/sfdx-git-delta#readme",
"scripts": {
"analysis": "codeclimate analyze",
"audit:fix": "npm i --package-lock-only && npm audit fix && rm yarn.lock && yarn import && rm package-lock.json",
"audit:fix": "npm i --package-lock-only && npm audit fix && shx rm yarn.lock && yarn import && shx rm package-lock.json",
"clean": "shx rm -rf lib && shx rm -rf coverage && shx rm -rf .nyc_output && shx rm -f oclif.manifest.json && shx rm -rf sfdx-git-delta-v*.tgz && shx rm -rf stderr*.txt && shx rm -rf stdout*.txt",
"commit": "commit",
"increment:apiversion": "filename=`ls src/metadata/v*.json | tail -1` && version=${filename//[!0-9]/} && ((version++)) && targetname=\"src/metadata/v${version}.json\" && \\cp $filename $targetname",
"lint": "eslint src/",
"lint:fix": "eslint --fix src/",
"test": "jest",
"test:build:local": "rm -rf node_modules && yarn && yarn pack && yarn test",
"test:clear:cache": "jest --clearCache",
"test:coverage": "jest --coverage",
"test:debug": "node --inspect node_modules/.bin/jest",
"test:debug:break": "node --inspect-brk node_modules/.bin/jest",
"test": "yarn test:unit && yarn test:nut",
"test:unit": "jest",
"test:build:local": "shx rm -rf node_modules && yarn && yarn pack && yarn test",
"test:unit:clear:cache": "jest --clearCache",
"test:unit:coverage": "jest --coverage",
"test:unit:debug": "node --inspect node_modules/.bin/jest",
"test:unit:debug:break": "node --inspect-brk node_modules/.bin/jest",
"test:watch": "jest --watch",
"build": "rm -rf lib && tsc -b",
"postpack": "rm -f oclif.manifest.json && prettier --write README.md",
"test:nut": "nyc mocha **/*.nut.ts",
"build": "tsc -b",
"postpack": "shx rm -f oclif.manifest.json && prettier --write README.md",
"prebuild": "yarn clean",
"prepack": "yarn build && oclif-dev manifest && oclif-dev readme",
"prepare": "husky install",
"increment:apiversion": "filename=`ls src/metadata/v*.json | tail -1` && version=${filename//[!0-9]/} && ((version++)) && targetname=\"src/metadata/v${version}.json\" && \\cp $filename $targetname",
"upgrade:dependencies": "yarn yarn-upgrade-all"
},
"devDependencies": {
Expand All @@ -70,12 +74,16 @@
"@oclif/dev-cli": "^1.26.10",
"@oclif/plugin-help": "^5.2.8",
"@oclif/test": "^2.3.13",
"@salesforce/cli-plugins-testkit": "^3.3.1",
"@salesforce/dev-config": "^3.1.0",
"@salesforce/ts-sinon": "^1.4.6",
"@swc/core": "^1.3.42",
"@types/chai": "^4.3.4",
"@types/mocha": "^10.0.1",
"@types/node": "^18.15.11",
"@typescript-eslint/eslint-plugin": "^5.57.0",
"@typescript-eslint/parser": "^5.57.0",
"chai": "^4.3.7",
"eslint": "^8.37.0",
"eslint-config-prettier": "^8.8.0",
"eslint-config-salesforce-typescript": "^1.1.1",
Expand All @@ -85,9 +93,12 @@
"husky": "^8.0.3",
"jest": "^29.5.0",
"lint-staged": "^13.2.0",
"mocha": "^10.2.0",
"nyc": "^15.1.0",
"prettier": "^2.8.7",
"prettier-eslint": "^15.0.1",
"shx": "^0.3.4",
"sinon": "^15.0.3",
"ts-node": "^10.9.1",
"typescript": "^5.0.2",
"yarn-upgrade-all": "^0.7.2"
Expand Down
Loading

0 comments on commit f2d132d

Please sign in to comment.