Utilities for testing tmplr packages using jest.
npm i @tmplr/jest --save-dev
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.
-
fs
is a tmplr-compliance filesystem whose methods are also spiable Jest functions. -
log
is a change log recording all changes applied by executed runnables. -
scope
is 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. -
context
is an evaluation context (bound toscope
) specifically for evaluating expressions within tmplr recipes. -
varcontext
is 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 viavarprefix
option).