Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,52 @@
}
}
},
"nodejs-testing.testSpecifiers": {
"type": "array",
"markdownDescription": "_Advanced_: A list of specifiers that indicate test function to search for:\nIt defaults to:\n\n```json\n[\n {\n \"import\": \"node:test\",\n \"name\": [\"default\", \"it\", \"test\", \"describe\", \"suite\"]\n }\n]\n```\n\nBut in case your test function is wrapped, you can specify it with a relative import:\nNOTE: relative imports must be prefixed with ./\nNOTE: A `name` of \"default\" is special and means the default export of that module is a test function\n\n```json\n[\n {\n \"import\": \"./test/utils.js\",\n \"name\": \"test\"\n }\n]\n```\n",
"default": [
{
"import": "node:test",
"name": [
"default",
"it",
"test",
"describe",
"suite"
]
}
],
"items": {
"type": "object",
"default": {
"import": "node:test",
"name": [
"default",
"it",
"test",
"describe",
"suite"
]
},
"required": [
"import",
"name"
],
"properties": {
"import": {
"type": "string",
"markdownDescription": "A package specifier (i.e. node:test) or workspace-relative path beginning with ./ (like ./test/utils.js) that indicates where the 'test' function can be imported from in your codebase"
},
"name": {
"type": "array",
"markdownDescription": "A list of functions that are imported from `import` that should be treated as test functions, the special name 'default' refers to the default export of a module",
"items": {
"type": "string"
}
}
}
}
},
"nodejs-testing.envFile": {
"type": "string",
"markdownDescription": "Absolute path to a file containing environment variable definitions.\n\nNote: template parameters like ${workspaceFolder} will be resolved.",
Expand Down
306 changes: 306 additions & 0 deletions src/__snapshots__/parsing.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -669,3 +669,309 @@ exports[`extract > works with string literals 1`] = `
},
]
`;

exports[`extract tests with custom specifiers > extracts default import tests 1`] = `
[
{
"children": [
{
"children": [],
"fn": "test",
"location": SourceLocation {
"end": Position {
"column": 4,
"line": 8,
},
"start": Position {
"column": 2,
"line": 6,
},
},
"name": "nested test",
},
],
"fn": "test",
"location": SourceLocation {
"end": Position {
"column": 2,
"line": 9,
},
"start": Position {
"column": 0,
"line": 4,
},
},
"name": "default import test",
},
]
`;

exports[`extract tests with custom specifiers > extracts named import tests 1`] = `
[
{
"children": [],
"fn": "wrappedTest",
"location": SourceLocation {
"end": Position {
"column": 6,
"line": 4,
},
"start": Position {
"column": 4,
"line": 2,
},
},
"name": "addition",
},
]
`;

exports[`extract tests with custom specifiers > extracts renamed named import test 1`] = `
[
{
"children": [],
"fn": "wrappedTest",
"location": SourceLocation {
"end": Position {
"column": 6,
"line": 4,
},
"start": Position {
"column": 4,
"line": 2,
},
},
"name": "addition",
},
]
`;

exports[`extract tests with custom specifiers > extracts renamed named import tests 1`] = `
[
{
"children": [],
"fn": "wrappedTest",
"location": SourceLocation {
"end": Position {
"column": 6,
"line": 4,
},
"start": Position {
"column": 4,
"line": 2,
},
},
"name": "addition",
},
]
`;

exports[`extract tests with custom specifiers > extracts star import tests 1`] = `
[
{
"children": [
{
"children": [],
"fn": "specialTest",
"location": SourceLocation {
"end": Position {
"column": 8,
"line": 7,
},
"start": Position {
"column": 6,
"line": 5,
},
},
"name": "subtest",
},
],
"fn": "specialTest",
"location": SourceLocation {
"end": Position {
"column": 6,
"line": 8,
},
"start": Position {
"column": 4,
"line": 2,
},
},
"name": "addition",
},
]
`;

exports[`extract with custom test specifiers in commonjs code > extracts aliased require 1`] = `
[
{
"children": [
{
"children": [],
"fn": "it",
"location": SourceLocation {
"end": Position {
"column": 4,
"line": 7,
},
"start": Position {
"column": 2,
"line": 5,
},
},
"name": "nested test",
},
],
"fn": "describe",
"location": SourceLocation {
"end": Position {
"column": 2,
"line": 8,
},
"start": Position {
"column": 0,
"line": 3,
},
},
"name": "destructured test",
},
]
`;

exports[`extract with custom test specifiers in commonjs code > extracts default require tests 1`] = `
[
{
"children": [
{
"children": [],
"fn": "test",
"location": SourceLocation {
"end": Position {
"column": 4,
"line": 7,
},
"start": Position {
"column": 2,
"line": 5,
},
},
"name": "nested test",
},
],
"fn": "test",
"location": SourceLocation {
"end": Position {
"column": 2,
"line": 8,
},
"start": Position {
"column": 0,
"line": 3,
},
},
"name": "default import test",
},
]
`;

exports[`extract with custom test specifiers in commonjs code > extracts destructed require 1`] = `
[
{
"children": [
{
"children": [],
"fn": "it",
"location": SourceLocation {
"end": Position {
"column": 4,
"line": 7,
},
"start": Position {
"column": 2,
"line": 5,
},
},
"name": "nested test",
},
],
"fn": "describe",
"location": SourceLocation {
"end": Position {
"column": 2,
"line": 8,
},
"start": Position {
"column": 0,
"line": 3,
},
},
"name": "destructured test",
},
]
`;

exports[`extract with custom test specifiers in commonjs code > extracts ts import mangled 1`] = `
[
{
"children": [
{
"children": [],
"fn": "it",
"location": SourceLocation {
"end": Position {
"column": 6,
"line": 8,
},
"start": Position {
"column": 4,
"line": 6,
},
},
"name": "addition",
},
{
"children": [],
"fn": "it",
"location": SourceLocation {
"end": Position {
"column": 6,
"line": 11,
},
"start": Position {
"column": 4,
"line": 9,
},
},
"name": "addition",
},
{
"children": [],
"fn": "it",
"location": SourceLocation {
"end": Position {
"column": 6,
"line": 14,
},
"start": Position {
"column": 4,
"line": 12,
},
},
"name": "subtraction",
},
],
"fn": "describe",
"location": SourceLocation {
"end": Position {
"column": 2,
"line": 15,
},
"start": Position {
"column": 0,
"line": 5,
},
},
"name": "math",
},
]
`;
Loading