From f154303f7606427ef1c9bc24fd0a78171cba76bb Mon Sep 17 00:00:00 2001 From: davidodenwald Date: Sun, 19 Mar 2023 18:02:07 +0100 Subject: [PATCH 1/3] add test coverage and check html files on watch mode --- .gitignore | 3 ++- jest.config.js | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index ab84829..c5d44aa 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ .vscode node_modules -lib \ No newline at end of file +lib +coverage \ No newline at end of file diff --git a/jest.config.js b/jest.config.js index 1c2f24e..644f56c 100644 --- a/jest.config.js +++ b/jest.config.js @@ -1,4 +1,8 @@ +const { defaults } = require("jest-config"); + /** @type {import('@jest/types').Config.InitialOptions} */ module.exports = () => ({ preset: "ts-jest", + moduleFileExtensions: [...defaults.moduleFileExtensions, "html"], + collectCoverage: true, }); From 74228f1fb36adad3b5c109f99cd4d3f24f093f90 Mon Sep 17 00:00:00 2001 From: davidodenwald Date: Sun, 19 Mar 2023 18:02:41 +0100 Subject: [PATCH 2/3] add locStart and locEnd tests --- test/plugin.test.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/test/plugin.test.ts b/test/plugin.test.ts index 99d954d..3831bb3 100644 --- a/test/plugin.test.ts +++ b/test/plugin.test.ts @@ -1,6 +1,6 @@ import { existsSync, readdirSync, readFileSync } from "fs"; import { join } from "path"; -import { format, Options } from "prettier"; +import { format, Options, ParserOptions } from "prettier"; import * as jinjaPlugin from "../src/index"; const prettify = (code: string, options: Options) => @@ -42,3 +42,13 @@ tests.forEach((test) => { } }); }); + +test("node has correct locStart and -End", () => { + const plugin = jinjaPlugin.parsers["jinja-template"]; + + const ast = plugin.parse(`

{{ test }}

`, {}, {} as ParserOptions); + const node = Object.values(ast.nodes)[0]!; + + expect(plugin.locStart(node)).toEqual(3); + expect(plugin.locEnd(node)).toEqual(13); +}); From c4a4618840a57cb6a7e0f556553f5f9ca727fa52 Mon Sep 17 00:00:00 2001 From: davidodenwald Date: Sun, 19 Mar 2023 18:03:21 +0100 Subject: [PATCH 3/3] add coverage upload to github ci --- .github/workflows/node.js.yml | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/.github/workflows/node.js.yml b/.github/workflows/node.js.yml index a542dcc..c6d8894 100644 --- a/.github/workflows/node.js.yml +++ b/.github/workflows/node.js.yml @@ -17,6 +17,14 @@ jobs: with: node-version: ${{ matrix.node-version }} cache: "npm" - - run: npm install -f - - run: npm run build - - run: npm run test + - name: Install dependencies + run: npm install -f + + - name: Build project + run: npm run build + + - name: Run tests + run: npm run test + + - name: Upload coverage + uses: codecov/codecov-action@v1