diff --git a/package.json b/package.json index 3f6e722..c0d176b 100644 --- a/package.json +++ b/package.json @@ -10,6 +10,7 @@ }, "devDependencies": { "@mdx-js/react": "^3.0.0", + "@types/node": "^20.11.16", "markdownlint": "~0.33.0", "prettier": "^3.2.5", "react": "^18.2.0", diff --git a/packages/stylelint-config-ali/package.json b/packages/stylelint-config-ali/package.json index 857ece8..eac69c9 100644 --- a/packages/stylelint-config-ali/package.json +++ b/packages/stylelint-config-ali/package.json @@ -35,7 +35,7 @@ ], "license": "MIT", "scripts": { - "test": "mocha ./test/*.test.js" + "test": "rive test" }, "dependencies": { "postcss": "^8.4.29", @@ -48,7 +48,6 @@ "stylelint": "^16.0.0" }, "devDependencies": { - "mocha": "^10.2.0", "stylelint": "^16.0.0", "stylelint-scss": "^6.0.0" } diff --git a/packages/stylelint-config-ali/test/rules-validate.test.js b/packages/stylelint-config-ali/test/rules-validate.test.js deleted file mode 100644 index a571915..0000000 --- a/packages/stylelint-config-ali/test/rules-validate.test.js +++ /dev/null @@ -1,114 +0,0 @@ -/** - * 验证规则是否生效 - * 目前需肉眼逐条观察 - */ - -const assert = require('assert'); -const stylelint = require('stylelint'); -const path = require('path'); - -function isObject(obj) { - return typeof obj === 'object' && obj !== null; -} - -describe('test/rules-validate.test.js', () => { - it('Validate default', async () => { - const filePaths = [path.join(__dirname, './fixtures/index.css')]; - - const result = await stylelint.lint({ - configFile: path.join(__dirname, '../index.js'), - files: filePaths, - fix: false, - }); - - if (result && result.errored) { - const filesResult = JSON.parse(result.output || '[]') || []; - filesResult.forEach((fileResult) => { - console.log(`========= ${filePaths} ==========`); - console.log(fileResult.warnings); - }); - - assert.ok(filesResult.length !== 0); - } - }); - - it('Validate sass', async () => { - const filePaths = [path.join(__dirname, './fixtures/sass-test.scss')]; - - const result = await stylelint.lint({ - configFile: path.join(__dirname, '../index.js'), - files: filePaths, - fix: false, - }); - - if (result && result.errored) { - const filesResult = JSON.parse(result.output || '[]') || []; - filesResult.forEach((fileResult) => { - console.log(`========= ${filePaths} ==========`); - console.log(fileResult.warnings); - }); - - assert.ok(filesResult.length !== 0); - } - }); - - it('Validate less', async () => { - const filePaths = [path.join(__dirname, './fixtures/less-test.less')]; - - const result = await stylelint.lint({ - configFile: path.join(__dirname, '../index.js'), - files: filePaths, - fix: false, - }); - - if (result && result.errored) { - const filesResult = JSON.parse(result.output || '[]') || []; - filesResult.forEach((fileResult) => { - console.log(`========= ${filePaths} ==========`); - console.log(fileResult.warnings); - }); - - assert.ok(filesResult.length !== 0); - } - }); - - it('Validate miniapp', async () => { - const filePaths = [path.join(__dirname, './fixtures/miniapp.acss')]; - - const result = await stylelint.lint({ - configFile: path.join(__dirname, '../index.js'), - files: filePaths, - fix: false, - }); - - if (result && result.errored) { - const filesResult = JSON.parse(result.output || '[]') || []; - filesResult.forEach((fileResult) => { - console.log(`========= ${filePaths} ==========`); - console.log(fileResult.warnings); - }); - - assert.ok(filesResult.length === 0); - } - }); - - it('Validate css-module', async () => { - const filePaths = [path.join(__dirname, './fixtures/css-module.scss')]; - - const result = await stylelint.lint({ - configFile: path.join(__dirname, '../index.js'), - files: filePaths, - fix: false, - }); - - if (result && result.errored) { - const filesResult = JSON.parse(result.output || '[]') || []; - filesResult.forEach((fileResult) => { - console.log(`========= ${filePaths} ==========`); - console.log(fileResult.warnings); - }); - - assert.ok(filesResult.length === 0); - } - }); -}); diff --git a/packages/stylelint-config-ali/test/rules-validate.test.ts b/packages/stylelint-config-ali/test/rules-validate.test.ts new file mode 100644 index 0000000..70d9b2d --- /dev/null +++ b/packages/stylelint-config-ali/test/rules-validate.test.ts @@ -0,0 +1,87 @@ +import { readFile } from 'fs/promises'; +import { join } from 'path'; +import stylelint from 'stylelint'; +import config from '../index'; + +describe('test/rules-validate.test.js', () => { + it('Validate default', async () => { + const result = await stylelint.lint({ + config: config as any, + code: await readFile(join(import.meta.dirname, 'fixtures/index.css'), 'utf-8'), + fix: false, + }); + + if (result && result.errored) { + const filesResult = JSON.parse(result.report || '[]') || []; + filesResult.forEach((fileResult) => { + console.log(fileResult.warnings); + }); + + expect(filesResult.length).toBeGreaterThan(0); + } + }); + + it('Validate sass', async () => { + const result = await stylelint.lint({ + config: config as any, + code: await readFile(join(import.meta.dirname, 'fixtures/sass-test.scss'), 'utf-8'), + fix: false, + }); + + if (result && result.errored) { + } + console.log(result.results); + expect(result.results.length).toBeGreaterThan(0); + }); + + it('Validate less', async () => { + const result = await stylelint.lint({ + config: config as any, + code: await readFile(join(import.meta.dirname, 'fixtures/less-test.less'), 'utf-8'), + fix: false, + }); + + if (result && result.errored) { + const filesResult = JSON.parse(result.report || '[]') || []; + filesResult.forEach((fileResult) => { + console.log(fileResult.warnings); + }); + + expect(filesResult.length).toBeGreaterThan(0); + } + }); + + it('Validate miniapp', async () => { + const result = await stylelint.lint({ + config: config as any, + code: await readFile(join(import.meta.dirname, 'fixtures/miniapp.acss'), 'utf-8'), + fix: false, + }); + + if (result && result.errored) { + const filesResult = JSON.parse(result.report || '[]') || []; + filesResult.forEach((fileResult) => { + console.log(fileResult.warnings); + }); + + expect(filesResult.length).toBe(0); + } + }); + + it('Validate css-module', async () => { + const result = await stylelint.lint({ + config: config as any, + code: await readFile(join(import.meta.dirname, 'fixtures/css-module.scss'), 'utf-8'), + fix: false, + }); + + if (result && result.errored) { + const filesResult = JSON.parse(result.report || '[]') || []; + filesResult.forEach((fileResult) => { + console.log(fileResult.warnings); + }); + + expect(filesResult.length).toBe(0); + } + }); +}); diff --git a/tsconfig.json b/tsconfig.json index 6212117..7938150 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,8 +1,16 @@ { "compilerOptions": { "target": "es2015", - "module": "es2015", - "moduleResolution": "node16", - "jsx": "react-jsx" - } + "module": "esnext", + "esModuleInterop": true, + "resolveJsonModule": true, + "types": ["node", "rive/globals"], + "lib": ["esnext"], + "allowJs": true, + "checkJs": false, + "skipLibCheck": true, + "moduleResolution": "node", + "isolatedModules": true + }, + "exclude": [".rive", "build", "coverage", "dist", "node_modules"] }