0.3.0 ⢠Published 1 year ago
@tmplr/jest v0.3.0
@tmplr/jest
Utilities for testing tmplr packages using jest.
npm i @tmplr/jest --save-devUsage
You need to have Jest installed and setup. Utilities provided by this package are only usable where Jest's globals are registered in the environment.
import { createTestSetup } from '@tmplr/jest'
test('stuff work ...', async () => {
const { fs, log, scope, context, varcontext } = createTestSetup({
files: {
'/some/file.txt': 'its content',
'relative.yml': 'some other content',
},
remotes: {
'https://github.com/user/repo': {
'README.md': 'some content',
'other-file.js': 'console.log("HOLA!")',
}
},
providers: {
stuff: {
thingy: async () => 'Ladida'
}
},
})
// đ write tests here ...
})âď¸ createTestSetup() function gets a test environment (with filesystem, available remotes, and data providers) and provides the basic primitives
allowing you to create core tmplr constructs (such as runnables and executions) and test their behavior in the test environment you have created.
fsis a tmplr-compliance filesystem whose methods are also spiable Jest functions.logis a change log recording all changes applied by executed runnables.scopeis the main execution scope, variables read by runnables will be available here, as will values provided via specified providers. Its methods are also spiable Jest functions.contextis an evaluation context (bound toscope) specifically for evaluating expressions within tmplr recipes.varcontextis an external evaluation context, which is suitable for evaluating expressions in other files. In this context, only variables stored during execution are available (through a special namespace, which can be specified viavarprefixoption).
â ď¸â ď¸ WORK IN PROGRESS. DO NOT USE. â ď¸â ď¸