Compare commits

...

3 commits

Author SHA1 Message Date
davidodenwald
c4a4618840 add coverage upload to github ci 2023-03-19 18:07:13 +01:00
davidodenwald
74228f1fb3 add locStart and locEnd tests 2023-03-19 18:07:13 +01:00
davidodenwald
f154303f76 add test coverage and check html files on watch mode 2023-03-19 18:02:19 +01:00
4 changed files with 28 additions and 5 deletions

View file

@ -17,6 +17,14 @@ jobs:
with: with:
node-version: ${{ matrix.node-version }} node-version: ${{ matrix.node-version }}
cache: "npm" cache: "npm"
- run: npm install -f - name: Install dependencies
- run: npm run build run: npm install -f
- run: npm run test
- name: Build project
run: npm run build
- name: Run tests
run: npm run test
- name: Upload coverage
uses: codecov/codecov-action@v1

1
.gitignore vendored
View file

@ -1,3 +1,4 @@
.vscode .vscode
node_modules node_modules
lib lib
coverage

View file

@ -1,4 +1,8 @@
const { defaults } = require("jest-config");
/** @type {import('@jest/types').Config.InitialOptions} */ /** @type {import('@jest/types').Config.InitialOptions} */
module.exports = () => ({ module.exports = () => ({
preset: "ts-jest", preset: "ts-jest",
moduleFileExtensions: [...defaults.moduleFileExtensions, "html"],
collectCoverage: true,
}); });

View file

@ -1,6 +1,6 @@
import { existsSync, readdirSync, readFileSync } from "fs"; import { existsSync, readdirSync, readFileSync } from "fs";
import { join } from "path"; import { join } from "path";
import { format, Options } from "prettier"; import { format, Options, ParserOptions } from "prettier";
import * as jinjaPlugin from "../src/index"; import * as jinjaPlugin from "../src/index";
const prettify = (code: string, options: Options) => 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(`<p>{{ test }}</p>`, {}, {} as ParserOptions);
const node = Object.values(ast.nodes)[0]!;
expect(plugin.locStart(node)).toEqual(3);
expect(plugin.locEnd(node)).toEqual(13);
});