/**
* createRuntime picks its materializer from the RELEASE's runtime kind.
*
* It used to hardcode nodeMaterialize. That is correct for every node/bare app —
* which is most of them, and is why nothing caught it — and silently wrong for a
* godot one: the npm layout would be written for an app that needs the godot
* layout, producing an install that exists, reports success, and does not run.
*
* The live registry entries carry the field (hyper-tps resolves with
* runtime:"bare"), even though release-registry.js's schema comment predates it.
*
* Run: bare test/materializer-selection.test.js
*/
import test from 'brittle'
import { selectMaterializer } from '../lib/runtime-factory.js'
import { materialize as nodeMaterialize } from '../lib/materializers/node.js'
import { materialize as godotMaterialize } from '../lib/materializers/godot.js'
test('node and bare share the npm layout', (t) => {
t.is(selectMaterializer('node'), nodeMaterialize)
t.is(selectMaterializer('bare'), nodeMaterialize, 'bare apps are npm-shaped too')
})
test('godot gets the godot layout', (t) => {
t.is(selectMaterializer('godot'), godotMaterialize)
t.not(selectMaterializer('godot'), nodeMaterialize, 'the bug this test exists for')
})
test('an absent runtime defaults to node', (t) => {
// Entries published before the field existed have no runtime; app.js's live
// path defaults them the same way (`entry.runtime || 'node'`).
t.is(selectMaterializer(undefined), nodeMaterialize)
t.is(selectMaterializer(null), nodeMaterialize)
t.is(selectMaterializer(''), nodeMaterialize)
})
test('an unknown runtime THROWS rather than guessing', (t) => {
// Defaulting would write the wrong layout and call it a success. A release
// naming a runtime this pgh does not have is a pgh too old for that release.
t.exception(() => selectMaterializer('unity'), /no materializer for runtime: unity/)
})