Skip to content

Commit 36ebdfa

Browse files
committed
add unit testing before publish
1 parent 094fb50 commit 36ebdfa

File tree

6 files changed

+81
-5
lines changed

6 files changed

+81
-5
lines changed

.github/workflows/publish.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,19 @@ on:
88
types: [published]
99

1010
jobs:
11+
test:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v3
15+
- uses: actions/setup-node@v3
16+
with:
17+
node-version: 18
18+
- run: npm ci
19+
- run: npm run test
20+
1121
publish-vsce:
22+
needs: test
23+
if: ${{ success() }}
1224
runs-on: ubuntu-latest
1325
steps:
1426
- uses: actions/checkout@v3

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,6 @@ node_modules
55
*.vsix
66
*.log
77
.DS_Store
8-
.test
8+
!test
9+
test/**
10+
!test/**.test.js

.vscodeignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
.vscode/**
22
.gitignore
33
CHANGELOG.md
4-
.test/**
4+
test/**

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ Fixed for any bug fixes.
99
Security to invite users to upgrade in case of vulnerabilities.
1010
-->
1111

12+
## 3.2.0 - 2023/02/27
13+
14+
### Added
15+
16+
- Unit test before publish task
17+
1218
## 3.1.2 - 2022/12/14
1319

1420
### Fixed

package.json

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "arrow-function-snippets",
33
"description": "VS Code Arrow function snippets for JS and TS",
4-
"version": "3.1.2",
4+
"version": "3.2.0",
55
"displayName": "Arrow Function Snippets",
66
"publisher": "deinsoftware",
77
"icon": "images/light-icon.png",
@@ -165,8 +165,16 @@
165165
}
166166
]
167167
},
168+
"scripts": {
169+
"test": "vitest --run --reporter verbose",
170+
"test:w": "vitest",
171+
"test:ui": "vitest --ui"
172+
},
168173
"volta": {
169-
"node": "18.7.0",
170-
"npm": "8.15.0"
174+
"node": "18.14.2",
175+
"npm": "9.5.0"
176+
},
177+
"devDependencies": {
178+
"vitest": "0.29.1"
171179
}
172180
}

test/snippets.test.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import { it, expect, describe } from 'vitest'
2+
3+
const arraysSnippets = require("../snippets/arrays.json")
4+
const arrowSnippets = require("../snippets/arrow.json")
5+
const promiseSnippets = require("../snippets/promise.json")
6+
const functionJsSnippets = require("../snippets/function-js.json")
7+
const functionTsSnippets = require("../snippets/var-ts.json")
8+
9+
const snippets = {
10+
...arraysSnippets,
11+
...arrowSnippets,
12+
...promiseSnippets,
13+
...functionJsSnippets,
14+
...functionTsSnippets,
15+
}
16+
17+
const unique = (xs) => [...new Set(xs)]
18+
19+
describe("snippets.json", () => {
20+
it("has entries", () => {
21+
expect(Object.keys(snippets).length).toBeGreaterThan(0)
22+
})
23+
24+
it("has unique prefixes", () => {
25+
const prefixes = Object.values(snippets).map((x) => x.prefix)
26+
expect(prefixes).toEqual(unique(prefixes))
27+
})
28+
29+
describe.each(Object.keys(snippets))("%s", (k) => {
30+
it("has prefix", () => {
31+
const { prefix } = snippets[k]
32+
expect(prefix).toBeDefined()
33+
expect(prefix).not.toEqual("")
34+
})
35+
36+
it("has body", () => {
37+
const { body } = snippets[k]
38+
expect(body).toBeDefined()
39+
expect(body).not.toEqual("")
40+
})
41+
42+
it("has description", () => {
43+
const { description } = snippets[k]
44+
expect(description).toBeDefined()
45+
expect(description).not.toEqual("")
46+
})
47+
})
48+
})

0 commit comments

Comments
 (0)