Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
textlint-tester
Advanced tools
Mocha test helper library for textlint rule.
npm install --save-dev textlint-tester mocha
textlint-tester
import TextLintTester from "textlint-tester";
// a rule for testing
import rule from "textlint-rule-no-todo";
const tester = new TextLintTester();
// ruleName, rule, { valid, invalid }
tester.run("rule name", rule, {
valid: [
"This is ok",
],
invalid: [
// line, column
{
text: "- [ ] string",
errors: [
{
message: "Found TODO: '- [ ] string'",
range: [2, 6]
}
]
}
]
});
$ npx mocha test/
TextLintTester#run
has two signatures.
TextLintTester#run(ruleName, rule, {valid=[], invalid=[]})
)TextLintTester#run(testName, testConfig, {valid=[], invalid=[]})
){string} ruleName
ruleName is a name of the rule.{TextlintRuleCreator} rule
rule is textlint rule.{string} testName
testName is a name of the test.{TestConfig} testConfig
testConfig is the configuration object for the test.TestConfig
is defined as follows:
export declare type TestConfig = {
plugins?: {
pluginId: string; // name of plugin
plugin: TextlintPluginCreator; // textlint plugin
options?: any; // options for plugin
}[];
rules: {
ruleId: string; // name of rule
rule: TextlintRuleCreator; // textlint rule
options?: any; // options for rule
}[];
};
testConfig
object example:
tester.run("rule name", {
plugins: [
{
pluginId: "html",
plugin: htmlPlugin // = require("textlint-plugin-html")
}
],
rules: [
{
ruleId: "no-todo",
rule: noTodoRule // = require("textlint-rule-no-todo").default
},
{
ruleId: "max-number-of-lines",
rule: maxNumberOfLineRule, // = require("textlint-rule-max-number-of-lines")
options: {
max: 2
}
}
]
}, { ... })
{string[]|object[]} valid
valid is an array of text which should be passed.
object
if you want to specify some options. object
can have the following properties:
{string} text
: a text to be linted{string} ext
: an extension key. Default: .md
(Markdown){string} inputPath
: a test text filePath that prefer to text
property{string} description
: a description for the test case. This will be displayed as the result of the test.{object} options
: options to be passed to the rule. Will throw assertion error if testConfig
is specifiedTypeScript declaration is for valid as follows:
export declare type TesterValid = string | {
text?: string;
ext?: string;
inputPath?: string;
options?: any;
description?: string;
};
valid
object example:
test.run("test name", rule, {
valid: [
"text",
{ text: "text" },
{
text: "text",
options: {
"key": "value",
},
},
{
text: "<p>this sentence is parsed as HTML document.</p>",
ext: ".html",
},
]
});
{object[]} invalid
invalid is an array of object which should be failed.
object
can have the following properties:
{string} text
: a text to be linted.{string} inputPath
: a test text filePath that prefer to text
property.{string} output
: a fixed text.{string} ext
: an extension key.{string} description
: a description for the test case. This will be displayed as the result of the test.{object[]} errors
: an array of error objects which should be raised against the text.{object} options
: options to be passed to the rule. Will throw assertion error if testConfig
is specifiedTypeScript's declaration is as follows:
export declare type TesterInvalid = {
text?: string;
output?: string;
ext?: string;
inputPath?: string;
options?: any;
description?: string;
errors: {
ruleId?: string;
range?: readonly [startIndex: number, endIndex: number];
loc?: {
start: {
line: number;
column: number;
};
end: {
line: number;
column: number;
};
};
/**
* @deprecated use `range` option
*/
index?: number;
/**
* @deprecated use `loc` option
*/
line?: number;
/**
* @deprecated use `loc` option
*/
message?: string;
[index: string]: any;
}[];
};
invalid
object example:
test.run("rule name", rule, {
invalid:
[
{
text: "text",
output: "text",
ext: ".txt",
errors: [
{
messages: "expected message",
line: 1,
column: 1
}
]
}
]
})
test/example-test.js
:
import TextLintTester from "textlint-tester";
// a rule for testing
import rule from "textlint-rule-no-todo";
const tester = new TextLintTester();
// ruleName, rule, { valid, invalid }
tester.run("no-todo", rule, {
valid: [
"This is ok",
{
// text with options
text: "This is test",
options: {
"key": "value"
}
}
],
invalid: [
// range
{
inputPath: path.join(__dirname, "fixtures/text/ng.md"),
errors: [
{
message: "Found TODO: '- [ ] This is NG'",
range: [2, 6]
}
]
},
// loc
{
inputPath: path.join(__dirname, "fixtures/text/ng.md"),
errors: [
{
message: "Found TODO: '- [ ] This is NG'",
loc: {
start: {
line: 1,
column: 2
},
end: {
line: 1,
column: 6
}
}
}
]
},
// Depreacted way
// line, column
{
text: "- [ ] string",
errors: [
{
message: "Found TODO: '- [ ] string'",
line: 1,
column: 3
}
]
},
// index
{
text: "- [ ] string",
errors: [
{
message: "Found TODO: '- [ ] string'",
index: 2
}
]
},
{
text: "TODO: string",
options: { "key": "value" },
errors: [
{
message: "found TODO: 'TODO: string'",
line: 1,
column: 1
}
]
},
{
text: "TODO: string",
output: "string", // <= fixed output
errors: [
{
message: "found TODO: 'TODO: string'",
line: 1,
column: 1
}
]
}
]
});
See textlint-tester-test.ts
or textlint-tester-plugin.ts
for concrete examples.
git checkout -b my-new-feature
git commit -am 'Add some feature'
git push origin my-new-feature
MIT
FAQs
testing tool for textlint rule.
The npm package textlint-tester receives a total of 27,514 weekly downloads. As such, textlint-tester popularity was classified as popular.
We found that textlint-tester demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.