Skip to content

Commit

Permalink
test: change from jest to vitest
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasaarcoverde committed Nov 27, 2023
1 parent 31f241f commit 6596ccd
Show file tree
Hide file tree
Showing 9 changed files with 308 additions and 154 deletions.
1 change: 0 additions & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,4 @@ module.exports = {
'jest-watch-typeahead/filename',
'jest-watch-typeahead/testname',
],
preset: 'jest-preset-stylelint',
}
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,7 @@
"vitest": "0.34.6",
"stylelint": "^15.11.0",
"stylelint-prettier": "^4.0.2",
"@vtex/shoreline-stylelint": "workspace",
"jest-preset-stylelint": "^6.3.2"
"@vtex/shoreline-stylelint": "workspace"
},
"lint-staged": {
"*.{ts,tsx,js,jsx}": [
Expand Down
11 changes: 3 additions & 8 deletions packages/stylelint/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@
"scripts": {
"prebuild": "rm -rf dist",
"dev": "tsup --watch",
"build": "npm run prebuild && tsup",
"test": "jest"
"build": "npm run prebuild && tsup"
},
"repository": {
"directory": "packages/stylelint",
Expand All @@ -39,11 +38,7 @@
"stylelint": "^14.15.0 || ^15.0.0"
},
"devDependencies": {
"tsup": "7.2.0",
"jest-preset-stylelint": "^6.3.2"
"tsup": "7.2.0"
},
"dependencies": {},
"jest": {
"preset": "jest-preset-stylelint"
}
"dependencies": {}
}
2 changes: 0 additions & 2 deletions packages/stylelint/src/index.types.d.ts

This file was deleted.

47 changes: 0 additions & 47 deletions packages/stylelint/src/plugins/no-px-values/index.test.js

This file was deleted.

66 changes: 66 additions & 0 deletions packages/stylelint/src/plugins/no-px-values/index.vitest.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import { test, expect } from 'vitest'

const plugin = require('.')

const { ruleName, messages } = plugin

const stylelint = require('stylelint')

test('it allows the use of valid space values on space properties', async () => {
const code = `
margin: 1rem;
padding: 1rem 0.5rem;
padding-left: 1rem;
top: 16px;
`

const result = await stylelint.lint({
code,
config: { plugins: [plugin], rules: { [ruleName]: true } },
})

expect(result.results[0].warnings).toHaveLength(0)
})

test('it disallows the use of px values on space properties', async () => {
const code = `
margin: 16px;
`

const result = await stylelint.lint({
code,
config: {
plugins: [plugin],
rules: { [ruleName]: true },
},
})

expect(result.results[0].warnings).toHaveLength(1)

const warning = result.results[0].warnings[0]

expect(warning.rule).toBe(ruleName)
expect(warning.severity).toBe('error')
expect(warning.text).toBe(messages.expected('margin', '16px', '1rem'))
})

test('it fix the error of invalid space property value to a valid one', async () => {
const code = `
padding: 22px 8px;
`

const result = await stylelint.lint({
code,
config: {
fix: true,
plugins: [plugin],
rules: { [ruleName]: true },
},
})

expect(result.results[0].warnings).toHaveLength(0)

expect(result.output).toBe(`
padding: 1.375rem 0.5rem;
`)
})
39 changes: 0 additions & 39 deletions packages/stylelint/src/plugins/no-text-property/index.test.js

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import { test, expect } from 'vitest'

const plugin = require('.')

const { ruleName, messages } = plugin

const stylelint = require('stylelint')

test('it allows the use of valid typography properties and values', async () => {
const code = `
font: var(--sl-text-body-font);
`

const result = await stylelint.lint({
code,
config: { plugins: [plugin], rules: { [ruleName]: true } },
})

expect(result.results[0].warnings).toHaveLength(0)
})

test('it disallows the use of invalid typography properties', async () => {
const code = `
text: var(--sl-text-body);
`

const result = await stylelint.lint({
code,
config: { plugins: [plugin], rules: { [ruleName]: true } },
})

expect(result.results[0].warnings).toHaveLength(1)

const warning = result.results[0].warnings[0]

expect(warning.rule).toBe(ruleName)
expect(warning.severity).toBe('error')
expect(warning.text).toBe(messages.expected)
})

test('it fix the error of invalid typography property usage to a valid one', async () => {
const code = `
text: var(--sl-text-body);
`

const result = await stylelint.lint({
code,
config: {
fix: true,
plugins: [plugin],
rules: { [ruleName]: true },
},
})

expect(result.results[0].warnings).toHaveLength(0)

expect(result.results[0].warnings).toHaveLength(0)

expect(result.output).toBe(`
font: var(--sl-text-body-font);
letter-spacing: var(--sl-text-body-letter-spacing);
`)
})
Loading

0 comments on commit 6596ccd

Please sign in to comment.