Skip to content

Commit

Permalink
chore: use Vitest
Browse files Browse the repository at this point in the history
  • Loading branch information
weizhenye committed Jul 27, 2024
1 parent d7a51f5 commit 6ed2cc4
Show file tree
Hide file tree
Showing 35 changed files with 63 additions and 108 deletions.
1 change: 1 addition & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"ObjectPattern": { "multiline": true, "consistent": true }
}],
"import/extensions": ["error", "ignorePackages"],
"import/no-extraneous-dependencies": ["error", { "devDependencies": true }],
"import/prefer-default-export": 0
}
}
12 changes: 6 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,21 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@master
- uses: actions/checkout@main
- name: Use Node.js
uses: actions/setup-node@v1
uses: actions/setup-node@v4
with:
node-version: '12.x'
node-version: 22
- name: Install Dependencies
run: npm i
- name: Build
run: npm run build
- name: Test
run: npm test
run: npm run cover
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v1
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
file: ./coverage/lcov.info
file: ./coverage/clover.xml
if: github.event_name == 'push'
continue-on-error: true
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
npm-debug.log*
node_modules
coverage
temp
package-lock.json
13 changes: 6 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
# ass-compiler

[![GitHub Action](https://github.com/weizhenye/ass-compiler/workflows/CI/badge.svg)](https://github.com/weizhenye/ass-compiler/actions)
[![Coverage](https://badgen.net/codecov/c/github/weizhenye/ass-compiler?icon=codecov)](https://codecov.io/gh/weizhenye/ass-compiler)
[![Dependencies](https://badgen.net/david/dep/weizhenye/ass-compiler?icon=https://api.iconify.design/si-glyph:connect-2.svg?color=white)](https://david-dm.org/weizhenye/ass-compiler)
[![NPM version](https://badgen.net/npm/v/ass-compiler?icon=npm)](https://www.npmjs.com/package/ass-compiler)
[![License](https://badgen.net/npm/license/ass-compiler?icon=https://api.iconify.design/octicon:law.svg?color=white)](https://github.com/weizhenye/ass-compiler/blob/master/LICENSE)
[![File size](https://badgen.net/bundlephobia/minzip/ass-compiler?icon=https://api.iconify.design/ant-design:file-zip-outline.svg?color=white)](https://bundlephobia.com/result?p=ass-compiler)
[![jsDelivr](https://badgen.net/jsdelivr/hits/npm/ass-compiler?icon=https://api.iconify.design/simple-icons:jsdelivr.svg?color=white)](https://www.jsdelivr.com/package/npm/ass-compiler)
[![GitHub Action](https://img.shields.io/github/actions/workflow/status/weizhenye/ass-compiler/ci.yml?logo=github)](https://github.com/weizhenye/ass-compiler/actions)
[![Codecov](https://img.shields.io/codecov/c/gh/weizhenye/ass-compiler?logo=codecov)](https://codecov.io/gh/weizhenye/ass-compiler)
[![License](https://img.shields.io/npm/l/ass-compiler)](https://github.com/weizhenye/ass-compiler/blob/master/LICENSE)
[![NPM Version](https://img.shields.io/npm/v/ass-compiler?logo=npm)](https://www.npmjs.com/package/ass-compiler)
[![jsDelivr](https://img.shields.io/jsdelivr/npm/hm/ass-compiler?logo=jsdelivr)](https://www.jsdelivr.com/package/npm/ass-compiler)
[![File size](https://img.shields.io/bundlejs/size/ass-compiler)](https://bundlephobia.com/result?p=ass-compiler)

Parses and compiles ASS subtitle format to easy-to-use data structure.

Expand Down
27 changes: 11 additions & 16 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"name": "ass-compiler",
"version": "0.1.11",
"type": "module",
"description": "Parses and compiles ASS subtitle format to easy-to-use data structure.",
"main": "dist/ass-compiler.js",
"module": "src/index.js",
Expand All @@ -13,10 +14,9 @@
"types": "types/index.d.ts",
"scripts": {
"lint": "eslint src test",
"preunit": "rollup -c rollup.config.test.js",
"unit": "mocha temp/test.js",
"cover": "cross-env ISTANBUL_REPORT_DIR=coverage ISTANBUL_REPORTERS=text-summary,lcov npm run unit -- --reporter=mocha-istanbul",
"test": "npm run lint && npm run unit && npm run cover",
"unit": "vitest run",
"cover": "vitest run --coverage",
"test": "npm run lint && npm run unit",
"dev": "rollup -c -w",
"bundle": "rollup -c",
"minify": "uglifyjs dist/ass-compiler.js -m -o dist/ass-compiler.min.js",
Expand All @@ -43,19 +43,14 @@
},
"homepage": "https://ass.js.org/ass-compiler/",
"devDependencies": {
"chai": "^4.2.0",
"cross-env": "^7.0.2",
"eslint": "^6.8.0",
"eslint-config-airbnb-base": "^14.1.0",
"eslint-plugin-import": "^2.20.2",
"istanbul": "^0.4.5",
"mocha": "^7.1.1",
"mocha-istanbul": "^0.3.0",
"rollup": "^2.6.1",
"@vitest/coverage-v8": "^2.0.4",
"eslint": "^8.57.0",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-plugin-import": "npm:eslint-plugin-i@^2.29.1",
"rollup": "^4.19.0",
"rollup-plugin-buble": "^0.19.8",
"rollup-plugin-istanbul": "^2.0.1",
"rollup-plugin-multi-entry": "^2.1.0",
"rollup-plugin-replace": "^2.2.0",
"uglify-js": "^3.9.1"
"uglify-js": "^3.19.0",
"vitest": "^2.0.4"
}
}
15 changes: 0 additions & 15 deletions rollup.config.test.js

This file was deleted.

3 changes: 1 addition & 2 deletions src/compiler/dialogues.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { compileText } from './text.js';
import { assign } from '../utils.js';

export function compileDialogues({ styles, dialogues }) {
let minLayer = Infinity;
Expand All @@ -22,7 +21,7 @@ export function compileDialogues({ styles, dialogues }) {
});
const alignment = compiledText.alignment || stl.Alignment;
minLayer = Math.min(minLayer, dia.Layer);
results.push(assign({
results.push(Object.assign({
layer: dia.Layer,
start: dia.Start,
end: dia.End,
Expand Down
4 changes: 1 addition & 3 deletions src/compiler/drawing.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { assign } from '../utils.js';

function createCommand(arr) {
const cmd = {
type: null,
Expand Down Expand Up @@ -131,5 +129,5 @@ export function compileDrawing(rawCommands) {
)),
);

return assign({ instructions, d: toSVGPath(instructions) }, getViewBox(commands));
return Object.assign({ instructions, d: toSVGPath(instructions) }, getViewBox(commands));
}
6 changes: 2 additions & 4 deletions src/compiler/styles.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { assign } from '../utils.js';

// same as Aegisub
// https://github.com/Aegisub/Aegisub/blob/master/src/ass_style.h
const DEFAULT_STYLE = {
Expand Down Expand Up @@ -54,9 +52,9 @@ export function parseStyleColor(color) {

export function compileStyles({ info, style, defaultStyle }) {
const result = {};
const styles = [assign({}, defaultStyle, { Name: 'Default' })].concat(style);
const styles = [Object.assign({}, defaultStyle, { Name: 'Default' })].concat(style);
for (let i = 0; i < styles.length; i++) {
const s = assign({}, DEFAULT_STYLE, styles[i]);
const s = Object.assign({}, DEFAULT_STYLE, styles[i]);
// this behavior is same as Aegisub by black-box testing
if (/^(\*+)Default$/.test(s.Name)) {
s.Name = 'Default';
Expand Down
3 changes: 1 addition & 2 deletions src/compiler/tag.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { compileDrawing } from './drawing.js';
import { assign } from '../utils.js';

const tTags = [
'fs', 'fsp', 'clip',
Expand Down Expand Up @@ -79,7 +78,7 @@ export function compileTag(tag, key, presets = {}) {
tags.forEach((t) => {
const k = Object.keys(t)[0];
if (~tTags.indexOf(k) && !(k === 'clip' && !t[k].dots)) {
assign(compiledTag, compileTag(t, k, presets));
Object.assign(compiledTag, compileTag(t, k, presets));
}
});
return { t: { t1, t2, accel, tag: compiledTag } };
Expand Down
7 changes: 3 additions & 4 deletions src/compiler/text.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { compileDrawing } from './drawing.js';
import { compileTag } from './tag.js';
import { assign } from '../utils.js';

const a2an = [
null, 1, 2, 3,
Expand All @@ -11,7 +10,7 @@ const a2an = [
const globalTags = ['r', 'a', 'an', 'pos', 'org', 'move', 'fade', 'fad', 'clip'];

function inheritTag(pTag) {
return JSON.parse(JSON.stringify(assign({}, pTag, {
return JSON.parse(JSON.stringify(Object.assign({}, pTag, {
k: undefined,
kf: undefined,
ko: undefined,
Expand Down Expand Up @@ -59,7 +58,7 @@ export function compileText({ styles, style, parsed, start, end }) {
fragment.tag.t = fragment.tag.t || [];
fragment.tag.t.push(compiledTag.t);
} else {
assign(fragment.tag, compiledTag);
Object.assign(fragment.tag, compiledTag);
}
}
}
Expand All @@ -80,5 +79,5 @@ export function compileText({ styles, style, parsed, start, end }) {
}
slices.push(slice);

return assign({ alignment, slices }, pos, org, move, fade, clip);
return Object.assign({ alignment, slices }, pos, org, move, fade, clip);
}
6 changes: 3 additions & 3 deletions src/decompiler.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { stringifyInfo, stringifyTime, stringifyEffect } from './stringifier.js';
import { assign, stylesFormat, eventsFormat } from './utils.js';
import { stylesFormat, eventsFormat } from './utils.js';

export function decompileStyle({ style, tag }) {
const obj = assign({}, style, {
const obj = Object.assign({}, style, {
PrimaryColour: `&H${tag.a1}${tag.c1}`,
SecondaryColour: `&H${tag.a2}${tag.c2}`,
OutlineColour: `&H${tag.a3}${tag.c3}`,
Expand Down Expand Up @@ -117,7 +117,7 @@ export function decompileDialogue(dia, style) {
export function decompile({ info, width, height, collisions, styles, dialogues }) {
return [
'[Script Info]',
stringifyInfo(assign({}, info, {
stringifyInfo(Object.assign({}, info, {
PlayResX: width,
PlayResY: height,
Collisions: collisions,
Expand Down
4 changes: 1 addition & 3 deletions src/parser/style.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import { assign } from '../utils.js';

export function parseStyle(text, format) {
const values = text.match(/Style\s*:\s*(.*)/i)[1].split(/\s*,\s*/);
return assign({}, ...format.map((fmt, idx) => ({ [fmt]: values[idx] })));
return Object.assign({}, ...format.map((fmt, idx) => ({ [fmt]: values[idx] })));
}
15 changes: 0 additions & 15 deletions src/utils.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 0 additions & 8 deletions test/.eslintrc.json

This file was deleted.

2 changes: 1 addition & 1 deletion test/compiler/dialogues.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { expect } from 'chai';
import { describe, it, expect } from 'vitest';
import { parseDialogue } from '../../src/parser/dialogue.js';
import { compileDialogues } from '../../src/compiler/dialogues.js';
import { compileStyles } from '../../src/compiler/styles.js';
Expand Down
2 changes: 1 addition & 1 deletion test/compiler/drawing.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { expect } from 'chai';
import { describe, it, expect } from 'vitest';
import { parseDrawing } from '../../src/parser/drawing.js';
import { s2b, toSVGPath, compileDrawing } from '../../src/compiler/drawing.js';

Expand Down
2 changes: 1 addition & 1 deletion test/compiler/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { expect } from 'chai';
import { describe, it, expect } from 'vitest';
import { compile } from '../../src/compiler/index.js';
import { text } from '../fixtures/index.js';

Expand Down
2 changes: 1 addition & 1 deletion test/compiler/styles.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { expect } from 'chai';
import { describe, it, expect } from 'vitest';
import { parseStyle } from '../../src/parser/style.js';
import { parseStyleColor, compileStyles } from '../../src/compiler/styles.js';
import { stylesFormat } from '../../src/utils.js';
Expand Down
2 changes: 1 addition & 1 deletion test/compiler/tag.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { expect } from 'chai';
import { describe, it, expect } from 'vitest';
import { compileTag } from '../../src/compiler/tag.js';

describe('tag compiler', () => {
Expand Down
2 changes: 1 addition & 1 deletion test/compiler/text.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { expect } from 'chai';
import { describe, it, expect } from 'vitest';
import { parseText } from '../../src/parser/text.js';
import { compileStyles } from '../../src/compiler/styles.js';
import { compileText } from '../../src/compiler/text.js';
Expand Down
2 changes: 1 addition & 1 deletion test/decompiler.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { expect } from 'chai';
import { describe, it, expect } from 'vitest';
import { decompile, decompileDrawing, decompileTag, decompileText } from '../src/decompiler.js';
import { compiled, decompiled, compiled2, decompiled2 } from './fixtures/decompiler.js';

Expand Down
2 changes: 1 addition & 1 deletion test/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { expect } from 'chai';
import { describe, it, expect } from 'vitest';
import { parse, stringify, compile, decompile } from '../src/index.js';

describe('ass-compiler', () => {
Expand Down
2 changes: 1 addition & 1 deletion test/parser/dialogue.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { expect } from 'chai';
import { describe, it, expect } from 'vitest';
import { parseDialogue } from '../../src/parser/dialogue.js';
import { eventsFormat } from '../../src/utils.js';

Expand Down
2 changes: 1 addition & 1 deletion test/parser/drawing.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { expect } from 'chai';
import { describe, it, expect } from 'vitest';
import { parseDrawing } from '../../src/parser/drawing.js';

describe('drawing parser', () => {
Expand Down
2 changes: 1 addition & 1 deletion test/parser/effect.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { expect } from 'chai';
import { describe, it, expect } from 'vitest';
import { parseEffect } from '../../src/parser/effect.js';

describe('effect parser', () => {
Expand Down
2 changes: 1 addition & 1 deletion test/parser/format.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { expect } from 'chai';
import { describe, it, expect } from 'vitest';
import { parseFormat } from '../../src/parser/format.js';
import { stylesFormat, eventsFormat } from '../../src/utils.js';

Expand Down
2 changes: 1 addition & 1 deletion test/parser/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { expect } from 'chai';
import { describe, it, expect } from 'vitest';
import { parse } from '../../src/parser/index.js';
import { stylesFormat, eventsFormat } from '../../src/utils.js';
import { text } from '../fixtures/index.js';
Expand Down
2 changes: 1 addition & 1 deletion test/parser/style.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { expect } from 'chai';
import { describe, it, expect } from 'vitest';
import { parseStyle } from '../../src/parser/style.js';
import { stylesFormat } from '../../src/utils.js';

Expand Down
2 changes: 1 addition & 1 deletion test/parser/tag.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { expect } from 'chai';
import { describe, it, expect } from 'vitest';
import { parseTag } from '../../src/parser/tag.js';

describe('tag parser', () => {
Expand Down
2 changes: 1 addition & 1 deletion test/parser/tags.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { expect } from 'chai';
import { describe, it, expect } from 'vitest';
import { parseTags } from '../../src/parser/tags.js';

describe('tags parser', () => {
Expand Down
2 changes: 1 addition & 1 deletion test/parser/text.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { expect } from 'chai';
import { describe, it, expect } from 'vitest';
import { parseText } from '../../src/parser/text.js';

describe('text parser', () => {
Expand Down
2 changes: 1 addition & 1 deletion test/parser/time.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { expect } from 'chai';
import { describe, it, expect } from 'vitest';
import { parseTime } from '../../src/parser/time.js';

describe('time parser', () => {
Expand Down
2 changes: 1 addition & 1 deletion test/stringifier.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { expect } from 'chai';
import { describe, it, expect } from 'vitest';
import { stringifyTime, stringifyEffect, stringifyEvent, stringifyTag, stringify } from '../src/stringifier.js';
import { eventsFormat } from '../src/utils.js';
import { parsed, stringified, parsed2, stringified2 } from './fixtures/stringifier.js';
Expand Down
8 changes: 8 additions & 0 deletions vitest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { defineConfig } from 'vitest/config';

export default defineConfig({
test: {
include: 'test/**/*.js',
exclude: 'test/fixtures/*.js',
},
});

0 comments on commit 6ed2cc4

Please sign in to comment.