From 36ebdfadd7e7ee603a231e0d05d955995be08bf1 Mon Sep 17 00:00:00 2001 From: equiman Date: Mon, 27 Feb 2023 17:18:06 -0500 Subject: [PATCH] add unit testing before publish --- .github/workflows/publish.yml | 12 +++++++++ .gitignore | 4 ++- .vscodeignore | 2 +- CHANGELOG.md | 6 +++++ package.json | 14 +++++++--- test/snippets.test.js | 48 +++++++++++++++++++++++++++++++++++ 6 files changed, 81 insertions(+), 5 deletions(-) create mode 100644 test/snippets.test.js diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index eccc8cb..ef48537 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -8,7 +8,19 @@ on: types: [published] jobs: + test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + with: + node-version: 18 + - run: npm ci + - run: npm run test + publish-vsce: + needs: test + if: ${{ success() }} runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 diff --git a/.gitignore b/.gitignore index 5577439..5cbc5df 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,6 @@ node_modules *.vsix *.log .DS_Store -.test \ No newline at end of file +!test +test/** +!test/**.test.js diff --git a/.vscodeignore b/.vscodeignore index b8156c8..0f84e92 100644 --- a/.vscodeignore +++ b/.vscodeignore @@ -1,4 +1,4 @@ .vscode/** .gitignore CHANGELOG.md -.test/** +test/** diff --git a/CHANGELOG.md b/CHANGELOG.md index 77b5dee..eac3a82 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,12 @@ Fixed for any bug fixes. Security to invite users to upgrade in case of vulnerabilities. --> +## 3.2.0 - 2023/02/27 + +### Added + +- Unit test before publish task + ## 3.1.2 - 2022/12/14 ### Fixed diff --git a/package.json b/package.json index 68efa59..0847f90 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "arrow-function-snippets", "description": "VS Code Arrow function snippets for JS and TS", - "version": "3.1.2", + "version": "3.2.0", "displayName": "Arrow Function Snippets", "publisher": "deinsoftware", "icon": "images/light-icon.png", @@ -165,8 +165,16 @@ } ] }, + "scripts": { + "test": "vitest --run --reporter verbose", + "test:w": "vitest", + "test:ui": "vitest --ui" + }, "volta": { - "node": "18.7.0", - "npm": "8.15.0" + "node": "18.14.2", + "npm": "9.5.0" + }, + "devDependencies": { + "vitest": "0.29.1" } } diff --git a/test/snippets.test.js b/test/snippets.test.js new file mode 100644 index 0000000..5581392 --- /dev/null +++ b/test/snippets.test.js @@ -0,0 +1,48 @@ +import { it, expect, describe } from 'vitest' + +const arraysSnippets = require("../snippets/arrays.json") +const arrowSnippets = require("../snippets/arrow.json") +const promiseSnippets = require("../snippets/promise.json") +const functionJsSnippets = require("../snippets/function-js.json") +const functionTsSnippets = require("../snippets/var-ts.json") + +const snippets = { + ...arraysSnippets, + ...arrowSnippets, + ...promiseSnippets, + ...functionJsSnippets, + ...functionTsSnippets, +} + +const unique = (xs) => [...new Set(xs)] + +describe("snippets.json", () => { + it("has entries", () => { + expect(Object.keys(snippets).length).toBeGreaterThan(0) + }) + + it("has unique prefixes", () => { + const prefixes = Object.values(snippets).map((x) => x.prefix) + expect(prefixes).toEqual(unique(prefixes)) + }) + + describe.each(Object.keys(snippets))("%s", (k) => { + it("has prefix", () => { + const { prefix } = snippets[k] + expect(prefix).toBeDefined() + expect(prefix).not.toEqual("") + }) + + it("has body", () => { + const { body } = snippets[k] + expect(body).toBeDefined() + expect(body).not.toEqual("") + }) + + it("has description", () => { + const { description } = snippets[k] + expect(description).toBeDefined() + expect(description).not.toEqual("") + }) + }) +}) \ No newline at end of file