![PyPI Now Supports iOS and Android Wheels for Mobile Python Development](https://cdn.sanity.io/images/cgdhsj6q/production/96416c872705517a6a65ad9646ce3e7caef623a0-1024x1024.webp?w=400&fit=max&auto=format)
Security News
PyPI Now Supports iOS and Android Wheels for Mobile Python Development
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
resolve-uit-path
Advanced tools
Resolves the path from your spec file at __filename to the corresponding unit-in-test's file
TL;DR
:point_right: :scream: Node Native:
const unitInTest = require( '../../../../../../../../lib/path/back/to/the/module/with/the/unitInTest')
:point_right: :relieved: Babel Namespaces:
const unitInTest = require( '<lib>/path/back/to/the/module/with/the/unitInTest')
:point_right: :smiley: This here module:
const unitInTest = require( resolveUitPath( __filename ) )
If you define your test files within a spec or test folder at a path that matches your unit in test, you can use this module to get the path to the module to be tested.
For example, if your folder structure looked like this:
project/
├── lib
│ └── path
│ └── back
│ └── to
│ └── the
│ └── module
│ └── with
│ └── the
│ └── unitInTest
│ └── index.js
└── spec
└── lib
└── path
└── back
└── to
└── the
└── module
└── with
└── the
└── unitInTest
└── index.test.js
you would do something like this with relative paths:
const unitInTest = require( '../../../../../../../../lib/path/back/to/the/module/with/the/unitInTest')
or something like this with Babel Namespaces:
const unitInTest = require( '<lib>/path/back/to/the/module/with/the/unitInTest')
This might be fine once or twice, but the more you deal with highly modular code, the more tedious this gets.
Using this little library, you can do this instead in your test file
// file: spec/lib/path/back/to/the/module/with/the/unitInTest/index.test.js
const resolveUitPath = require( 'resolve-uit-path' )();
const uitPath = resolveUitPath( __filename );
describe( `The ${ uitPath } function`, ()=>{
it( 'should throw if called without arguments', ()=>{
const uit = require( uitPath );
expect( uit ).to.throw();
});
} );
The module allows you to configure, which type of extension you want to use for your test files. It defaults to .test.js
, but you can change that by instantiating it with an alternative specFileExtension
.
For example, if you used the -spec.js
extension instead of .test.js
, you would configure the module as shown below:
// file: spec/lib/path/back/to/the/module/with/the/unitInTest/index-spec.js
const resolveUitPath = require( 'resolve-uit-path' )( { specFileExtension: '-spec.js'});
const uitPath = resolveUitPath( __filename );
describe( `The ${ uitPath } function`, ()=>{
it( 'should throw if called without arguments', ()=>{
const uit = require( uitPath );
expect( uit ).to.throw();
});
} );
You can also configure the name of your spec folder:
// file: tests/lib/path/back/to/the/module/with/the/unitInTest/index.test.js
const resolveUitPath = require( 'resolve-uit-path' )( { specDirName: 'tests'});
const uitPath = resolveUitPath( __filename );
describe( `The ${ uitPath } function`, ()=>{
it( 'should throw if called without arguments', ()=>{
const uit = require( uitPath );
expect( uit ).to.throw();
});
} );
The library assumes that the level-difference between the spec and the uit is 1, meaning that you can store your test in spec
, tests
, specFiles
, etc, but within the spec folder itself, the path must match.
:white_check_mark: will work:
project
├── lib
│ └── path
└── spec
└── lib
└── path
:white_check_mark: will work:
project/
├── lib
│ └── path
└── tests
└── lib
└── path
:white_check_mark: will work for all spec folders
project
├── lib
│ ├── common
│ │ └── path
│ └── packages
│ ├── package-a
│ │ ├── lib
│ │ │ └── path
│ │ └── spec
│ │ └── lib
│ │ └── path
│ └── package-b
│ └── lib
│ └── path
└── spec
├── lib
│ └── common
│ └── path
└── packages
└── package-b
└── lib
└── path
:x: will not work
project
├── lib
│ └── path
└── spec
├── integration
│ └── lib
│ └── path
└── unit
└── lib
└── path
FAQs
Resolves the path from your spec file at __filename to the corresponding unit-in-test's file
The npm package resolve-uit-path receives a total of 2 weekly downloads. As such, resolve-uit-path popularity was classified as not popular.
We found that resolve-uit-path 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
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.