Skip to content

Commit

Permalink
test: add check to see if all the frameworks honors forced framework
Browse files Browse the repository at this point in the history
  • Loading branch information
pieh committed Sep 18, 2024
1 parent 22f4965 commit e71068a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
17 changes: 16 additions & 1 deletion packages/build-info/src/get-framework.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { test, expect, beforeEach } from 'vitest'
import { describe, test, expect, beforeEach } from 'vitest'

import { mockFileSystem } from '../tests/mock-file-system.js'

import { frameworks } from './frameworks/index.js'
import { getFramework } from './get-framework.js'
import { NodeFS } from './node/file-system.js'
import { Project } from './project.js'
Expand Down Expand Up @@ -52,3 +53,17 @@ test('should throw if a unknown framework was requested', async ({ fs }) => {
}
expect.assertions(1)
})

describe('Framework detection honors forced framework', () => {
for (const Framework of frameworks) {
test(Framework.name, async ({ fs }) => {
const cwd = mockFileSystem({})
const project = new Project(fs, cwd)
const framework = new Framework(project)

const detectedFramework = await getFramework(framework.id, project)

expect(detectedFramework.id).toBe(framework.id)
})
}
})
3 changes: 3 additions & 0 deletions packages/build-info/src/get-framework.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ export async function getFramework(frameworkId: FrameworkName, project: Project)
if (detected) {
return detected
}

// this indicate that framework's custom "detect" method doesn't honor the forced framework
throw new Error(`Forced framework "${frameworkId}" was not detected.`)
}

const frameworkIds = frameworkList
Expand Down

0 comments on commit e71068a

Please sign in to comment.