Skip to content

Commit

Permalink
spec: migrate to vitest (#130)
Browse files Browse the repository at this point in the history
Co-authored-by: Almanov Nikita <131481562+nikkeyl@users.noreply.github.com>
  • Loading branch information
github-actions[bot] and nikkeyl authored Mar 19, 2024
1 parent 21f0423 commit ea4d37b
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 70 deletions.
12 changes: 0 additions & 12 deletions .mocharc.json

This file was deleted.

10 changes: 5 additions & 5 deletions specs/creators/at-rule.spec.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
import { expect } from 'chai';
import { describe, beforeEach, it } from 'mocha';
import { beforeEach, describe, expect, test } from 'vitest';

import createAtRule from '../../src/creators/at-rule.ts';

describe('Create At Rule', () => {
let atRule: any;
let atRule: Function;

beforeEach(() => {
const addAtRule = async (name: string, hasBlock: boolean) => {
return createAtRule(name, hasBlock).then((argument) => {
expect(argument.name).equal(name);
expect(argument.hasBlock).equal(hasBlock);
expect(argument.type).equal('at-rule');
});
};

atRule = addAtRule;
});

it('create an object with args (name: String, hasBlock: true)', async () => {
test('create an object with args (name: String, hasBlock: true)', async () => {
return atRule('test-rule', true);
});

it('create an object with args (name: String, hasBlock: false)', async () => {
test('create an object with args (name: String, hasBlock: false)', async () => {
return atRule('test-rule', false);
});
});
8 changes: 5 additions & 3 deletions specs/creators/logical-group.spec.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import { expect } from 'chai';
import { describe, it } from 'mocha';
import { describe, expect, test } from 'vitest';

import createLogicalGroup from '../../src/creators/logical-group.ts';

describe('Create Logical Group', () => {
it('create an object with args (groupName: String, properties: [])', async () => {
test('create an object with args (groupName: String, properties: [])', async () => {
const properties = ['display', 'z-index'];

return createLogicalGroup('Test Group Name', properties).then((argument) => {
expect(argument.groupName).equal('Test Group Name');
expect(argument.properties).equal(properties);
expect(argument.emptyLineBefore).equal('always');
expect(argument.noEmptyLineBetween).equal(true);
expect(argument.order).equal('flexible');
});
});
});
17 changes: 8 additions & 9 deletions specs/creators/rule.spec.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { expect } from 'chai';
import { describe, beforeEach, it } from 'mocha';
import { beforeEach, describe, expect, test } from 'vitest';

import createRule from '../../src/creators/rule.ts';

describe('Create Rule', () => {
let rule: any;
let rule: Function;

beforeEach(() => {
const addRule = async (selector: string) => {
Expand All @@ -17,27 +16,27 @@ describe('Create Rule', () => {
rule = addRule;
});

it('create an object with argument (::pseudo-element)', async () => {
test('create an object with argument (::pseudo-element)', async () => {
return rule('::pseudo-element');
});

it('create an object with argument (:pseudo-class)', async () => {
test('create an object with argument (:pseudo-class)', async () => {
return rule(':pseudo-class');
});

it('create an object with argument (?\\[(.*)\\])', async () => {
test('create an object with argument (?\\[(.*)\\])', async () => {
return rule('?\\[(.*)\\]');
});

it('create an object with argument (?\\.(.*))', async () => {
test('create an object with argument (?\\.(.*))', async () => {
return rule('?\\.(.*)');
});

it('create an object with argument (--)', async () => {
test('create an object with argument (--)', async () => {
return rule('--');
});

it('create an object with argument (__)', async () => {
test('create an object with argument (__)', async () => {
return rule('__');
});
});
53 changes: 36 additions & 17 deletions specs/regex/bem-pattern.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { expect } from 'chai';
import { describe, it } from 'mocha';
import { describe, expect, test } from 'vitest';

import CSSRules from '../../src/rules/css.ts';

Expand All @@ -8,63 +7,83 @@ describe('BEM Class Pattern', () => {
CSSRules['selector-class-pattern'][0] as string,
);

it('block (block)', () => {
test('block (block)', () => {
expect('block').match(BEMClassPattern);
});

it('block (block-name)', () => {
test('block (block-name)', () => {
expect('block-name').match(BEMClassPattern);
});

it('block, modifier (block--modifier)', () => {
test('block (block-name-123)', () => {
expect('block-name-123').match(BEMClassPattern);
});

test('block, modifier (block--modifier)', () => {
expect('block--modifier').match(BEMClassPattern);
});

it('block, modifier (block-name--modifier-name)', () => {
test('block, modifier (block-name--modifier-name)', () => {
expect('block-name--modifier-name').match(BEMClassPattern);
});

it('block, modifier (block-name--modifier)', () => {
test('block, modifier (block-name--modifier)', () => {
expect('block-name--modifier').match(BEMClassPattern);
});

it('block, modifier (block--modifier-name)', () => {
test('block, modifier (block--modifier-name)', () => {
expect('block--modifier-name').match(BEMClassPattern);
});

it('block, element (block__element)', () => {
test('block, element (block__element)', () => {
expect('block__element').match(BEMClassPattern);
});

it('block, element (block-name__element-name)', () => {
test('block, element (block-name__element-name)', () => {
expect('block-name__element-name').match(BEMClassPattern);
});

it('block, element (block-name__element)', () => {
test('block, element (block-name__element)', () => {
expect('block-name__element').match(BEMClassPattern);
});

it('block, element (block__element-name)', () => {
test('block, element (block__element-name)', () => {
expect('block__element-name').match(BEMClassPattern);
});

it('block, element, modifier (block__element--modifier)', () => {
test('block, element, modifier (block__element--modifier)', () => {
expect('block__element--modifier').match(BEMClassPattern);
});

it('block, element, modifier (block-name__element-name--modifier-name)', () => {
test('block, element, modifier (block-name__element-name--modifier-name)', () => {
expect('block-name__element-name--modifier-name').match(BEMClassPattern);
});

it('block, element, modifier (block-name__element-name--modifier)', () => {
test('block, element, modifier (block-name__element-name--modifier)', () => {
expect('block-name__element-name--modifier').match(BEMClassPattern);
});

it('block, element, modifier (block-name__element--modifier-name)', () => {
test('block, element, modifier (block-name__element--modifier-name)', () => {
expect('block-name__element--modifier-name').match(BEMClassPattern);
});

it('block, element, modifier (block__element-name--modifier-name)', () => {
test('block, element, modifier (block__element-name--modifier-name)', () => {
expect('block__element-name--modifier-name').match(BEMClassPattern);
});

test('block, element, modifier (block__element_modifier)', () => {
expect('block__element_modifier').not.match(BEMClassPattern);
});

test('block (Block)', () => {
expect('Block').not.match(BEMClassPattern);
});

test('block (BlockElement)', () => {
expect('BlockElement').not.match(BEMClassPattern);
});

test('block (123)', () => {
expect('123').not.match(BEMClassPattern);
});
});
47 changes: 23 additions & 24 deletions specs/regex/regex.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { expect } from 'chai';
import { describe, it } from 'mocha';
import { describe, expect, test } from 'vitest';

import regex from '../../src/utils/regexps.ts';

Expand All @@ -10,91 +9,91 @@ describe('Nested Selectors Pattern', () => {
const CHILD_ATTRIBUTE = regex.child.ATTRIBUTE_PATTERN;
const CHILD_CLASS = regex.child.CLASS_PATTERN;

it('nested (&[attribute)', () => {
test('nested (&[attribute)', () => {
expect('&[attribute]').match(new RegExp(`&${NESTED_ATTRIBUTE}`));
});

it('nested (&[attribute] {})', () => {
test('nested (&[attribute] {})', () => {
expect('&[attribute] {}').match(new RegExp(`&${NESTED_ATTRIBUTE}`));
});

it('nested (&[attribute=value])', () => {
test('nested (&[attribute=value])', () => {
expect('&[attribute=value]').match(new RegExp(`&${NESTED_ATTRIBUTE}`));
});

it('nested (&[attribute*=value])', () => {
test('nested (&[attribute*=value])', () => {
expect('&[attribute*=value]').match(new RegExp(`&${NESTED_ATTRIBUTE}`));
});

it('nested (&[attribute=value] {})', () => {
test('nested (&[attribute=value] {})', () => {
expect('&[attribute=value] {}').match(new RegExp(`&${NESTED_ATTRIBUTE}`));
});

it('nested (&[attribute*=value] {})', () => {
test('nested (&[attribute*=value] {})', () => {
expect('&[attribute*=value] {}').match(new RegExp(`&${NESTED_ATTRIBUTE}`));
});

it('nested (&[attribute="value"])', () => {
test('nested (&[attribute="value"])', () => {
expect("&[attribute='value']").match(new RegExp(`&${NESTED_ATTRIBUTE}`));
});

it('nested (&[attribute*="value"])', () => {
test('nested (&[attribute*="value"])', () => {
expect("&[attribute*='value']").match(new RegExp(`&${NESTED_ATTRIBUTE}`));
});

it('nested (&[attribute="value"] {})', () => {
test('nested (&[attribute="value"] {})', () => {
expect("&[attribute='value'] {}").match(new RegExp(`&${NESTED_ATTRIBUTE}`));
});

it('nested (&[attribute*="value"] {})', () => {
test('nested (&[attribute*="value"] {})', () => {
expect("&[attribute*='value'] {}").match(new RegExp(`&${NESTED_ATTRIBUTE}`));
});

it("nested (&[attribute='value'])", () => {
test("nested (&[attribute='value'])", () => {
expect("&[attribute='value']").match(new RegExp(`&${NESTED_ATTRIBUTE}`));
});

it("nested (&[attribute*='value'])", () => {
test("nested (&[attribute*='value'])", () => {
expect("&[attribute*='value']").match(new RegExp(`&${NESTED_ATTRIBUTE}`));
});

it("nested (&[attribute='value'] {})", () => {
test("nested (&[attribute='value'] {})", () => {
expect("&[attribute='value'] {}").match(new RegExp(`&${NESTED_ATTRIBUTE}`));
});

it("nested (&[attribute*='value'] {})", () => {
test("nested (&[attribute*='value'] {})", () => {
expect("&[attribute*='value'] {}").match(new RegExp(`&${NESTED_ATTRIBUTE}`));
});

it('nested (&.class)', () => {
test('nested (&.class)', () => {
expect('&.class').match(new RegExp(`&${NESTED_CLASS}`));
});

it('nested (&.class {})', () => {
test('nested (&.class {})', () => {
expect('&.class {}').match(new RegExp(`&${NESTED_CLASS}`));
});

it('nested (&--modifier)', () => {
test('nested (&--modifier)', () => {
expect('&--modifier').match(new RegExp(`&${NESTED_MODIFIER}`));
});

it('nested (&--modifier {})', () => {
test('nested (&--modifier {})', () => {
expect('&--modifier {}').match(new RegExp(`&${NESTED_MODIFIER}`));
});

it('child ([attribute] &)', () => {
test('child ([attribute] &)', () => {
expect('[attribute] &').match(new RegExp(`&${CHILD_ATTRIBUTE}`));
});

it('child ([attribute] & {})', () => {
test('child ([attribute] & {})', () => {
expect('[attribute] & {}').match(new RegExp(`&${CHILD_ATTRIBUTE}`));
});

it('child (.class &)', () => {
test('child (.class &)', () => {
expect('.class &').match(new RegExp(`&${CHILD_CLASS}`));
});

it('child (.class & {})', () => {
test('child (.class & {})', () => {
expect('.class & {}').match(new RegExp(`&${CHILD_CLASS}`));
});
});
13 changes: 13 additions & 0 deletions vitest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { defineConfig } from 'vitest/config';

export default defineConfig({
test: {
include: ['specs/**/*.spec.ts'],
watch: false,
coverage: {
all: false,
provider: 'v8',
reporter: 'text',
},
},
});

0 comments on commit ea4d37b

Please sign in to comment.