-
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.
feature: use
vscode.workspace.fs
API to load Expo projects (#252)
* test: add tests for expo project and project cache * refactor: use `vscode.workspace.fs` API to load Expo projects * refactor: implement new `vscode.workspace.fs` API to load Expo projects * fix: use `path.posix.join` in `relativeUri` for Windows * refactor: drop `relativeUri` in favor of `vscode.Uri.joinPath`
- Loading branch information
Showing
10 changed files
with
142 additions
and
57 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 { readWorkspaceFile } from '../../utils/file'; | ||
import { ExpoProjectCache, findProjectFromWorkspaces } from '../project'; | ||
|
||
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', async () => { | ||
using projects = stubProjectCache(); | ||
const project = await 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', async () => { | ||
using projects = stubProjectCache(); | ||
const project = await 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 = await findProjectFromWorkspaces(projects, './manifest'); | ||
const workspace = vscode.workspace.workspaceFolders![0]; | ||
const packageUri = vscode.Uri.joinPath(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
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
Oops, something went wrong.