Comments (4)
@danez Thanks for the report and for using the template.
I can reproduce this locally.
I'll create a pull request to bring this preset up to date as it has fallen behind the setup we use in stylelint itself to test the built-in rules.
Am I right in thinking you want to use this preset to test a stylelint plugin you're writing, and you want to use the testRule
schema?
from jest-preset-stylelint.
Am I right in thinking you want to use this preset to test a stylelint plugin you're writing, and you want to use the testRule schema?
Exactly, although I also run into a different issue now: The plugin I have is about imports, and checks if the import is correct. But if stylelint was called with stdin content instead of a file we cannoot really resolve the import, so we skip the rule:
const source = root.source.input.file;
if (!source) {
return;
}
Now I cannot test this afaics because i cannot mock any of this. I could add an option for testing that skips this check, but wanted to ask first if there is something better you could think of?
from jest-preset-stylelint.
This preset may not be a good fit. It's mostly used to speed up writing countless (fixable) syntax tests, like so. As your plugin is concerned with resolving imports, I think you're best using the stylelint Node.js API directly so that you can use fixtures for your tests. You can use files
option when testing using fixtures. The code
option can be used to test your source conditional.
I've pulled out the bits from the testRule
function that I think are relevant to your needs:
const { lint } = require("stylelint");
const config = {
plugins: ["./lib/index.js"],
rules: {
"plugin/at-import-no-unresolveable": [true],
},
};
it("warns for unresolveable import", async () => {
const {
results: [{ warnings, parseErrors }],
} = await lint({
files: "fixtures/contains-unresolveable-import.css",
config,
});
expect(parseErrors).toHaveLength(0);
expect(warnings).toHaveLength(1);
const [{ line, column, text }] = warnings;
expect(text).toBe(
"Unexpected unresolveable import (plugin/at-import-no-unresolveable)"
);
expect(line).toBe(1);
expect(column).toBe(1);
});
it("doesn't warn for resolveable imports", async () => {
const {
results: [{ warnings, parseErrors }],
} = await lint({
files: "fixtures/contains-resolveable-import.css",
config,
});
expect(parseErrors).toHaveLength(0);
expect(warnings).toHaveLength(0);
});
it("doesn't warn for fileless sources", async () => {
const {
results: [{ warnings, parseErrors }],
} = await lint({
code: "@import url(unknown.css)",
config,
});
expect(parseErrors).toHaveLength(0);
expect(warnings).toHaveLength(0);
});
..
It sounds like a great plugin, by the way.
from jest-preset-stylelint.
Closed by #14, which fixes the TypeError
. We hope to release a new version later this week once we sort out compatibility with the rules built into stylelint. master
is good to go for plugins authors, though.
from jest-preset-stylelint.
Related Issues (12)
- Support `stylelint>=9.1` as peerDependencies HOT 1
- Add JSDoc for testRule HOT 3
- Adopting preset HOT 1
- Release 2.0.0 HOT 8
- Jest peerDependency HOT 1
- Release 3.0.0 HOT 1
- Grant access to publish NPM to other maintainers HOT 7
- Fix testing disable comment plugins by using `ignoreDisables` HOT 1
- Fix TypeScript errors HOT 1
- Assert plugin options validation HOT 2
- Add support for custom unfixable error messages
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jest-preset-stylelint.