Skip to content

Commit 6e75888

Browse files
authored
Merge pull request #1835 from contentstack/feat/DX-2334-add-unit-test-workflow
feat: Add workflow to run and validate unit tests
2 parents ad411a1 + f8e19dc commit 6e75888

File tree

5 files changed

+131
-198
lines changed

5 files changed

+131
-198
lines changed

.github/workflows/unit-test.yml

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
name: Run Unit Tests
2+
3+
on:
4+
pull_request:
5+
types: [opened, synchronize, reopened]
6+
7+
jobs:
8+
run-tests:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: Checkout code
12+
uses: actions/checkout@v4
13+
14+
- name: Set up Node.js
15+
uses: actions/setup-node@v4
16+
with:
17+
node-version: '22.x'
18+
19+
- name: Install dependencies for all plugins
20+
run: |
21+
npm run setup-repo-old
22+
23+
- name: Fetch latest references
24+
run: |
25+
git fetch --prune
26+
27+
- name: Identify Changed Plugins
28+
id: changes
29+
run: |
30+
echo "Finding changed files..."
31+
# Ensure both commit references are valid
32+
if [[ -z "${{ github.event.before }}" || -z "${{ github.sha }}" ]]; then
33+
echo "Error: Missing commit references"
34+
exit 1
35+
fi
36+
37+
CHANGED_FILES=$(git diff --name-only ${{ github.event.before }} ${{ github.sha }})
38+
echo "Changed files:"
39+
echo "$CHANGED_FILES"
40+
41+
# Identify affected plugins
42+
AFFECTED_PLUGINS=$(echo "$CHANGED_FILES" | grep -oP '(?<=^packages/)([^/]+)' | sort -u | tr '\n' ' ')
43+
echo "Affected plugins: $AFFECTED_PLUGINS"
44+
45+
# Set output for the next step
46+
echo "::set-output name=affected_plugins::$AFFECTED_PLUGINS"
47+
48+
- name: Run Unit Tests for Affected Plugins
49+
run: |
50+
for plugin in ${{ steps.changes.outputs.affected_plugins }}; do
51+
echo "Running tests for $plugin..."
52+
npm run test:unit --prefix ./packages/$plugin
53+
done

package-lock.json

Lines changed: 73 additions & 140 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/contentstack-audit/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@
7474
"test": "mocha --forbid-only \"test/**/*.test.ts\"",
7575
"version": "oclif readme && git add README.md",
7676
"clean": "rm -rf ./lib ./node_modules tsconfig.tsbuildinfo oclif.manifest.json",
77-
"test:unit:report": "nyc --extension .ts mocha --forbid-only \"test/unit/**/*.test.ts\""
77+
"test:unit:report": "nyc --extension .ts mocha --forbid-only \"test/unit/**/*.test.ts\"",
78+
"test:unit": "mocha --timeout 10000 --forbid-only \"test/unit/**/*.test.ts\""
7879
},
7980
"engines": {
8081
"node": ">=16"

packages/contentstack-audit/test/unit/commands/index.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ describe('Audit command', () => {
1010
filename!: string;
1111
} as FileTransportInstance;
1212

13-
describe('Audit run method', () => {
13+
describe('Audit run method:', () => {
1414
fancy
1515
.stdout({ print: process.env.PRINT === 'true' || false })
1616
.stub(winston.transports, 'File', () => fsTransport)

0 commit comments

Comments
 (0)