Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
@ayana/test
Advanced tools
With NPM
npm i @ayana/test typescript --save-dev
With Yarn
yarn add @ayana/test typescript --dev
Add the following scripts to your package.json
:
{
"name": "your-project",
...
"scripts": {
"test": "ayt test",
"cover": "ayt coverage"
}
}
By Ayana convention the code lives in the src
directory if it's an application and in the lib
directory if it's a library.
Files outside of these directories will be ignored.
Exclude .spec.ts
files in your tsconfig.json
(If you are using ayc
from @ayana/ts this step can be skipped):
{
...
"exclude": [
"./lib/**/*.spec.ts"
]
}
Create .spec.ts
files named after the file you want to test next to the file you want to test:
Say your file lives under lib/hello/Hello.ts
, then you would create a file for the tests at lib/hello/Hello.spec.ts
.
import '@ayana/test';
autoDescribe(function() { // autoDescribe will take the path after the lib or src folder and use it as the descriptor
describe('#constructor', function() {
it('should do a thing', function() {
});
});
});
Tests are written with mocha
. In addition there's also the global variables sinon
and expect
(powered by unexpected) available for usage in tests.
When using the import @ayana/test/di
this package adds another global variable called TestInjector
. Using this you can easily write Unit-Tests for components and the TestInjector
will automatically create a sinon stub for all required components.
import '@ayana/test/di';
import { Tested } from './Tested';
import { SomeDependency } from './SomeDependency';
autoDescribe(function() {
describe('#doSomething', function() {
it('should do a thing', function() {
const injector = TestInjector.test(Tested);
const tested = injector.getTested();
tested.doSomething();
expect(
injector.getStub(SomeDependency).someMethod.callCount,
'to be',
1
);
});
});
});
import { Inject } from '@ayana/di';
import { SomeDependency } from './SomeDependency';
export class Tested {
constructor(@Inject() private someDependency: SomeDependency) {}
doSomething() {
this.someDependency.someMethod();
}
}
export class SomeDependency {
someMethod() {
console.log('Does Something');
}
}
This might be caused by you having custom .d.ts
files in your project. ts-node
apperantly resolves custom .d.ts
files differently
than tsc
does.
You can find a way to fix this in the TS-Node README. You want to set the baseUrl
and the paths
array in the compilerOptions
in your tsconfig.json
like it's mentioned there.
If you get an error like this:
Experimental support for decorators is a feature that is subject to change in a future release. Set the 'experimentalDecorators' option in your 'tsconfig' or 'jsconfig' to remove this warning. ts(1219)
It is because you excluded the .spec.ts
in your main tsconfig.json
like mentioned above so that config doesn't apply to .spec.ts
files anymore.
If you need to use decorators in your tests, then you currently have to create a second file for the actual build (tsconfig.prod.json
is recommended) and move the exclude property for the .spec.ts
files there:
{
"extends": "./tsconfig.json",
"exclude": [
"./lib/**/*.spec.ts"
]
}
Also you need to update your build command to tsc -p tsconfig.prod.json
. Running tsc
should work just fine, however the output directory will also contain the compiled files of the tests which you might not want in your npm package or deployed application.
FAQs
Testing libraries and config for Ayana projects
The npm package @ayana/test receives a total of 32 weekly downloads. As such, @ayana/test popularity was classified as not popular.
We found that @ayana/test demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 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.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.