Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 25 additions & 6 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
name: Run unit test and collect coverage
name: Run unit test & coverage
on:
push:
branches: [master]
paths-ignore:
- 'dbml-homepage/**'
- "dbml-homepage/**"
pull_request:
branches: [master]
types: [opened, synchronize]
paths-ignore:
- 'dbml-homepage/**'
- "dbml-homepage/**"
jobs:
build:
runs-on: ubuntu-22.04
Expand Down Expand Up @@ -92,19 +92,38 @@ jobs:
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: 'yarn'
cache: "yarn"
- name: Install dependencies
run: yarn install --frozen-lockfile
- name: Build packages
run: yarn build
- name: Run unit test and coverage
- name: Run coverage test
run: yarn coverage
- name: Generate coverage report
id: coverage
run: node .github/workflows/scripts/collect-coverage.js
- name: Upload coverage test
if: always()
uses: actions/upload-artifact@v4
with:
name: coverage-report.md
path: ./coverage-report.md
include-hidden-files: true

comment-coverage:
runs-on: ubuntu-22.04
timeout-minutes: 5
continue-on-error: true
needs: build
steps:
- name: Download test coverage
uses: actions/download-artifact@v4
with:
name: coverage-report.md
path: ./coverage-report.md
- name: Comment PR with coverage report
uses: marocchino/sticky-pull-request-comment@v2
if: github.event_name == 'pull_request'
with:
recreate: true
path: coverage-report.md
path: ./coverage-report.md
33 changes: 25 additions & 8 deletions packages/dbml-parse/__tests__/snapshots/binder/binder.test.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,37 @@
import { readFileSync } from 'fs';
import path from 'path';
import { readFileSync } from 'node:fs';
import path from 'node:path';
import { describe, expect, it } from 'vitest';
import Lexer from '@/core/lexer/lexer';
import Parser from '@/core/parser/parser';
import { NodeSymbolIdGenerator } from '@/core/analyzer/symbol/symbols';
import { SyntaxNodeIdGenerator } from '@/core/parser/nodes';
import type { ProgramNode } from '@/core/parser/nodes';
import Analyzer from '@/core/analyzer/analyzer';
import { serialize, scanTestNames } from '@tests/utils';
import { scanTestNames, toSnapshot } from '@tests/utils';
import type Report from '@/core/report';
import Compiler from '@/compiler';

function serializeBinderResult (compiler: Compiler, report: Report<ProgramNode>): string {
const value = report.getValue();
const errors = report.getErrors();
const warnings = report.getWarnings();
return JSON.stringify(toSnapshot(compiler, {
program: value,
errors,
warnings,
}), null, 2);
}

describe('[snapshot] binder', () => {
const testNames = scanTestNames(path.resolve(__dirname, './input/'));

testNames.forEach((testName) => {
const program = readFileSync(path.resolve(__dirname, `./input/${testName}.in.dbml`), 'utf-8');
const symbolIdGenerator = new NodeSymbolIdGenerator();
const nodeIdGenerator = new SyntaxNodeIdGenerator();

const compiler = new Compiler();
compiler.setSource(program);

// @ts-expect-error "Current workaround to use compiler but only trigger analyzer"
const { nodeIdGenerator, symbolIdGenerator } = compiler;

const report = new Lexer(program)
.lex()
.chain((tokens) => {
Expand All @@ -23,7 +40,7 @@ describe('[snapshot] binder', () => {
.chain(({ ast }) => {
return new Analyzer(ast, symbolIdGenerator).analyze();
});
const output = serialize(report, true);
const output = serializeBinderResult(compiler, report);

it(testName, () => expect(output).toMatchFileSnapshot(path.resolve(__dirname, `./output/${testName}.out.json`)));
});
Expand Down
Loading
Loading