
Security News
Socket Releases Free Certified Patches for Critical vm2 Sandbox Escape
A critical vm2 sandbox escape can allow untrusted JavaScript to break isolation and execute commands on the host Node.js process.
test-file-magic
Advanced tools
Switch between source and test files, automatically scaffolding your tests if they don't exist.
This is an open-source VS Code extension created by Herb Caudill.
Going back and forth between a test file and its source is something that I do many, many times a day; and every time I do it, I have to think about where test files are stored relative to source files. It's a tiny bit of cognitive friction that I'd like to get rid of.
Creating a test file is also a chore. It's a tiny chore, to be sure, but it's also a distraction and a source of friction: I have to think about what naming convention we use, where it should be saved, and I have to put some boilerplate in place before I can start actually writing a test.
Test File Magic gets rid of that friction with a single keyboard shortcut, alt+T alt+T, to do all of those things:
describe block, etc.)
You can also invoke this command from the context menu: Right-click on a file and choose Toggle Test β Source to jump from a source file to a test file. Do the same to jump back.
This command is also available from the command palette.
Different developers, teams, and projects organize their tests differently:
tests folder in each directory; still others put them in a root-level tests folder with a parallel file structure.test or spec between the filename and extension (e.g. foo.test.js).The Test File Magic extension can be customized to work with many common patterns for organizing test files.
By default, it assumes that your tests are organized like this:
π [workspace root]
π src
π index.js
π index.test.js
π foo.js
π foo.test.js
π lib
π bar.js
π bar.test.js
Test File Magic offers these settings:
| Name | Description | Default |
|---|---|---|
testFileMagic.fileExtensions | File extensions for source and test files (comma-separated). | ts, js, tsx, jsx |
testFileMagic.testKeyword | Keyword for test filenames, inserted before the file extension. For example, if set to spec, the test file for foo.ts is foo.spec.ts. | test |
testFileMagic.sourceDirectory | Name of the directory containing source files. | src |
testFileMagic.testDirectory | Name of the directory (or directories) containing test files. If this is not set, each test file lives alongside its corresponding source file. | (notΒ set) |
testFileMagic.testDirectoryLocation | If testFileMagic.testDirectory is set, this indicates whether there is just one test directory or many:
| root |
testFileMagic.testFileTemplate | Template to use when creating a new test file for a module. (See below) |
Note that either testFileMagic.testDirectory or testFileMagic.testKeyword (or both) need to be set.
As with all settings, you can change these at the user level, or at the workspace level so that you can adapt the extension's behavior to the file naming scheme used on each project you work on.
π [workspace root]
π src
π index.js
π index.spec.js π‘Έ custom keyword for tests (`spec` instead of `test`)
π foo.js
π foo.spec.js π‘Έ
π lib
π bar.js
π bar.spec.js π‘Έ
{
"testFileMagic.testKeyword": "spec"
}
π [workspace root]
π src
π index.js
π foo.js
π tests π‘Έ each folder has a `tests` subdirectory
π index.test.js
π foo.test.js
π lib
π bar.js
π tests π‘Έ
π bar.test.js
{
"testFileMagic.testDirectory": "tests",
"testFileMagic.testDirectoryLocation": "alongside"
}
π [workspace root]
π src
π index.js
π lib
π bar.js
π tests π‘Έ root-level `tests` directory with parallel file structure
π index.test.js
π lib
π bar.test.js
{
"testFileMagic.testDirectory": "tests",
"testFileMagic.testDirectoryLocation": "root"
}
π [workspace root]
π src
π index.js
π lib
π bar.js
π tests
π index.js π‘Έ test files don't include a `test` or `spec` keyword
π lib
π bar.js π‘Έ
{
"testFileMagic.testKeyword": "",
"testFileMagic.testDirectory": "tests",
"testFileMagic.testDirectoryLocation": "root"
}
If you try to go to a test file that doesn't exist, the file will be created. For example, if you are in an untested file called foo.ts and you invoke this extension, you'll get a new file like this:
import { foo } from './foo'
describe('foo', () => {
it('should work', () => {
})
})
This template is defined in settings as an array of strings.
[
"import { ${moduleName} } from '${modulePath}'",
"",
"describe('${moduleName}', () => {",
" it('should work', () => {",
"",
" })",
"})"
]
${moduleName} will be replaced the current filename, without the extension.${modulePath} will be replaced with the relative path from the new test file to the source file.FAQs
Switch between source and test files, automatically scaffolding your tests if they don't exist.
The npm package test-file-magic receives a total of 1 weekly downloads. As such, test-file-magic popularity was classified as not popular.
We found that test-file-magic demonstrated a not healthy version release cadence and project activity because the last version was released a year ago.Β It has 1 open source maintainer 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
A critical vm2 sandbox escape can allow untrusted JavaScript to break isolation and execute commands on the host Node.js process.

Research
Five malicious NuGet packages impersonate Chinese .NET libraries to deploy a stealer targeting browser credentials, crypto wallets, SSH keys, and local files.

Security News
pnpm 11 turns on a 1-day Minimum Release Age and blocks exotic subdeps by default, adding safeguards against fast-moving supply chain attacks.