-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add tests for expo project and project cache
- Loading branch information
Showing
5 changed files
with
94 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import { expect } from 'chai'; | ||
import { findNodeAtLocation } from 'jsonc-parser'; | ||
import vscode from 'vscode'; | ||
|
||
import { ExpoProjectCache, findProjectFromWorkspaces } from '../project'; | ||
import { readWorkspaceFile, relativeUri } from '../../utils/file'; | ||
|
||
describe('ExpoProjectCache', () => { | ||
it('adds disposable to extension context', () => { | ||
const subscriptions: any[] = []; | ||
using _projects = stubProjectCache(subscriptions); | ||
|
||
expect(subscriptions).to.have.length(1); | ||
}); | ||
}); | ||
|
||
describe('findProjectFromWorkspaces', () => { | ||
it('returns projct from workspace using relative path', () => { | ||
using projects = stubProjectCache(); | ||
const project = findProjectFromWorkspaces(projects, './manifest'); | ||
|
||
expect(project).to.exist; | ||
}); | ||
|
||
it('returned project contains parsed package file', () => { | ||
using projects = stubProjectCache(); | ||
const project = findProjectFromWorkspaces(projects, './manifest'); | ||
|
||
expect(project?.package.tree).to.exist; | ||
expect(findNodeAtLocation(project!.package.tree, ['name'])!.value).to.equal('manifest'); | ||
}); | ||
|
||
it('returned project contains parsed expo manifest file', () => { | ||
using projects = stubProjectCache(); | ||
const project = findProjectFromWorkspaces(projects, './manifest'); | ||
|
||
expect(project?.manifest!.tree).to.exist; | ||
expect(findNodeAtLocation(project!.manifest!.tree, ['name'])!.value).to.equal('manifest'); | ||
}); | ||
}); | ||
|
||
describe('ExpoProject', () => { | ||
it('returns expo version from package file', async () => { | ||
using projects = stubProjectCache(); | ||
|
||
const project = findProjectFromWorkspaces(projects, './manifest'); | ||
const workspace = vscode.workspace.workspaceFolders![0]; | ||
const packageUri = relativeUri(workspace.uri, 'manifest/package.json'); | ||
const packageFile = JSON.parse(await readWorkspaceFile(packageUri)); | ||
|
||
expect(project?.expoVersion).to.equal(packageFile.dependencies.expo); | ||
}); | ||
}); | ||
|
||
function stubProjectCache(subscriptions: vscode.ExtensionContext['subscriptions'] = []) { | ||
const stubProjectCache = new ExpoProjectCache({ subscriptions }); | ||
|
||
// @ts-expect-error | ||
stubProjectCache[Symbol.dispose] = () => stubProjectCache.dispose(); | ||
|
||
return stubProjectCache as Disposable & typeof stubProjectCache; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters