Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
test('define checker as IoC container binding', async (assert) => {
const ioc = new Ioc()
const application = new Application(__dirname, ioc, {}, {})
const healthCheck = new HealthCheck(application)
class DbChecker {
public async report () {
return {
health: {
healthy: true,
},
}
}
}
ioc.bind('App/Checkers/Db', () => {
return new DbChecker()
})
test('register view provider', async (assert) => {
const ioc = new Ioc()
ioc.bind('Adonis/Core/Env', () => {
return {
get () {},
}
})
ioc.bind('Adonis/Core/Application', () => {
return {
viewsPath () {
return __dirname
},
}
})
const registrar = new Registrar(ioc)
test('register global boolean flags', async (assert) => {
assert.plan(2)
const app = new Application(__dirname, new Ioc(), {}, {})
const kernel = new Kernel(app)
kernel.flag('ansi', (ansi, parsed) => {
assert.equal(ansi, true)
assert.deepEqual(parsed, { _: [], ansi: true })
}, {})
const argv = ['--ansi']
await kernel.handle(argv)
})
test('make a provider inside the default directory', async (assert) => {
await fs.add('.adonisrc.json', JSON.stringify({}))
const app = new Application(fs.basePath, new Ioc(), {}, {})
const provider = new MakeProvider(app, new Kernel(app))
provider.name = 'app'
await provider.handle()
const AppProvider = await fs.get('providers/AppProvider.ts')
const ProviderTemplate = await templates.get('provider.txt')
assert.deepEqual(
toNewlineArray(AppProvider),
toNewlineArray(ProviderTemplate.replace('${filename}', 'AppProvider')),
)
const rcContents = await fs.get('.adonisrc.json')
assert.deepEqual(JSON.parse(rcContents), {
providers: ['./providers/AppProvider'],
})
test('execute instructions defined in package.json file', async (assert) => {
process.env.ADONIS_ACE_CWD = fs.basePath
await fs.add('node_modules/@adonisjs/sample/package.json', JSON.stringify({
name: '@adonisjs/sample',
adonisjs: {
env: {
'PORT': '3333',
},
},
}))
const app = new Application(fs.basePath, new Ioc(), {}, {})
const invoke = new Invoke(app, new Kernel(app))
invoke.name = '@adonisjs/sample'
await invoke.handle()
const envFile = await fs.fsExtra.readFile(join(fs.basePath, '.env'), 'utf-8')
const envExampleFile = await fs.fsExtra.readFile(join(fs.basePath, '.env.example'), 'utf-8')
assert.equal(envFile.trim(), 'PORT=3333')
assert.equal(envExampleFile.trim(), 'PORT=')
})
})
test('share route and signedRoute methods with view', async (assert) => {
assert.plan(6)
const ioc = new Ioc()
ioc.bind('Adonis/Core/Env', () => {
return {
get () {},
}
})
ioc.bind('Adonis/Core/Application', () => {
return {
viewsPath () {
return __dirname
},
}
})
ioc.bind('Adonis/Core/HttpContext', () => {
test('convert camelcase command path to colon seperated name', async (assert) => {
await fs.add('.adonisrc.json', JSON.stringify({
directories: {
commands: './foo',
},
}))
const app = new Application(fs.basePath, new Ioc(), {}, {})
const command = new MakeCommand(app, new Kernel(app))
command.name = 'RunInstructions'
await command.handle()
const GreetCommand = await fs.get('foo/RunInstructions.ts')
const CommandTemplate = await templates.get('command.txt')
assert.deepEqual(
toNewlineArray(GreetCommand),
toNewlineArray(
CommandTemplate
.replace('${filename}', 'RunInstructions')
.replace('${toCommandName(filename)}', 'run:instructions'),
),
)
})
private _instantiateIoCContainer () {
this.ioc = new Ioc(false)
global['use'] = this.ioc.use.bind(this.ioc)
global['make'] = this.ioc.make.bind(this.ioc)
this.ioc.singleton('container', () => this.ioc)
}
public setup (): ApplicationContract {
const ioc = new Ioc()
/**
* Adding IoC container resolver methods to the globals.
*/
global[Symbol.for('ioc.use')] = ioc.use.bind(ioc)
global[Symbol.for('ioc.make')] = ioc.make.bind(ioc)
global[Symbol.for('ioc.call')] = ioc.call.bind(ioc)
const adonisCorePkgFile = findPkg(join(__dirname, '..', '..')).next().value
const appPkgFile = findPkg(this.appRoot).next().value
const pkgFile = {
name: appPkgFile ? appPkgFile.name : 'adonis',
version: appPkgFile ? appPkgFile.version : '0.0.0',
adonisVersion: adonisCorePkgFile!.version,
}
private setupApplication () {
let rcContents = {}
try {
rcContents = esmRequire(join(this.appRoot, '.adonisrc.json'))
} catch (error) {
if (isMissingModuleError(error)) {
throw new AceRuntimeException('Make sure the project root has ".adonisrc.json"')
}
throw error
}
this.application = new Application(this.appRoot, new Ioc(), rcContents, {})
}