Impostazioni in kscript.json
{
"packages": ["KScript.IO"], // imported by every script, including tests
"test": {
"include": ["tests/**/*.test.kscript"], // default: **/*.test.kscript and **/*.test.ks.xml
"exclude": ["tests/slow"], // default: _templates, node_modules, .git
"timeout": 10, // seconds per test; 0 for no limit (default 10)
"packages": ["KScript.Terminal"], // imported by test files only
"env": "test", // the environment tests run in (KSCRIPT_ENV)
"database": "memory" // KScript.Data: a database in memory per test file, or config
}
}timeout: … su un test ha la precedenza su --timeout, che ha la precedenza su test.timeout.
test.env è l'ambiente in cui girano i test, quindi kscript.test.json si sovrappone alle impostazioni di kscript.json (vedi Impostazioni). I template di progetto per API e fullstack lo usano per dare ai test un database in memoria.
kscript test --env staging e un KSCRIPT_ENV già impostato hanno la precedenza su test.env.
I test che usano KScript.Data ottengono un proprio database in memoria, indipendentemente dalla configurazione, a meno che test.database non sia config. Le modifiche di ciascun test vengono annullate al termine. Questo vale anche per gli utenti basati su un modello in http.auth.users. Una route che un test chiama con @api() usa lo stesso database, nella transazione del test: la route vede i record creati dal test, il test vede ciò che la route ha salvato, e entrambi vengono annullati insieme.
Ogni file di test riceve anche cartelle temporanee per l'app, per l'autenticazione basata su file, inclusi gli store configurati in http.auth.folder, e per @storage(). I comandi e le chiamate locali a @api() condividono queste cartelle all'interno del file. Il runner le rimuove al termine del file, anche in caso di errore. Usa una fixture nel file di test o un hook di setup quando i test richiedono utenti o file predefiniti.