Skip to content

Commit 06a934a

Browse files
fcollonvaltelamonian
authored andcommitted
Add unit tests
1 parent cfe1cc9 commit 06a934a

File tree

8 files changed

+797
-104
lines changed

8 files changed

+797
-104
lines changed

jest.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ module.exports = {
1414
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
1515
setupFiles: ['<rootDir>/testutils/jest-setup-files.js'],
1616
testPathIgnorePatterns: ['/lib/', '/node_modules/'],
17-
testRegex: '/tests/test-.*/.*.spec.ts[x]?$',
17+
testRegex: '/tests/.*.spec.ts[x]?$',
1818
transformIgnorePatterns: ['/node_modules/(?!(@jupyterlab/.*)/)'],
1919
globals: {
2020
'ts-jest': {

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
"devDependencies": {
6969
"@babel/core": "^7.5.0",
7070
"@babel/preset-env": "^7.5.0",
71+
"@jupyterlab/testutils": "^1.1.0",
7172
"@types/codemirror": "^0.0.79",
7273
"@types/enzyme": "3.1.15",
7374
"@types/jest": "^24",

src/model.ts

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -65,37 +65,40 @@ export class GitExtension implements IGitExtension, IDisposable {
6565
oldValue: this._pathRepository
6666
};
6767
if (v === null) {
68-
this._pathRepository = null;
69-
if (change.newValue !== change.oldValue) {
70-
this._refreshStatus();
71-
this._repositoryChanged.emit(change);
72-
}
68+
this._pendingReadyPromise += 1;
69+
this._readyPromise.then(() => {
70+
this._pathRepository = null;
71+
this._pendingReadyPromise -= 1;
72+
73+
if (change.newValue !== change.oldValue) {
74+
this.refreshStatus();
75+
this._repositoryChanged.emit(change);
76+
}
77+
});
7378
} else {
74-
void this.ready.then(() => {
75-
this._isReady = false;
76-
this._readyPromise = this.showTopLevel(v)
77-
.then(results => {
78-
if (results.code === 0) {
79-
this._pathRepository = results.top_repo_path;
80-
change.newValue = results.top_repo_path;
81-
} else {
82-
this._pathRepository = null;
83-
}
84-
85-
if (change.newValue !== change.oldValue) {
86-
this._refreshStatus();
87-
this._repositoryChanged.emit(change);
88-
}
89-
})
90-
.catch(reason => {
91-
console.error(
92-
`Fail to find git top level for path ${v}.\n${reason}`
93-
);
94-
95-
void this._readyPromise.then(() => {
96-
this._isReady = true;
97-
});
98-
});
79+
const currentReady = this._readyPromise;
80+
this._pendingReadyPromise += 1;
81+
this._readyPromise = Promise.all([currentReady, this.showTopLevel(v)])
82+
.then(r => {
83+
const results = r[1];
84+
if (results.code === 0) {
85+
this._pathRepository = results.top_repo_path;
86+
change.newValue = results.top_repo_path;
87+
} else {
88+
this._pathRepository = null;
89+
}
90+
91+
if (change.newValue !== change.oldValue) {
92+
this.refreshStatus();
93+
this._repositoryChanged.emit(change);
94+
}
95+
})
96+
.catch(reason => {
97+
console.error(`Fail to find git top level for path ${v}.\n${reason}`);
98+
});
99+
100+
void this._readyPromise.then(() => {
101+
this._pendingReadyPromise -= 1;
99102
});
100103
}
101104
}
@@ -162,12 +165,9 @@ export class GitExtension implements IGitExtension, IDisposable {
162165
return null;
163166
}
164167

165-
return (
166-
'/' +
167-
PathExt.join(
168-
PathExt.relative(this._serverRoot, this.pathRepository),
169-
path || ''
170-
)
168+
return PathExt.join(
169+
PathExt.relative(this._serverRoot, this.pathRepository),
170+
path || ''
171171
);
172172
}
173173

@@ -760,7 +760,7 @@ export class GitExtension implements IGitExtension, IDisposable {
760760
* Test whether the model is ready.
761761
*/
762762
get isReady(): boolean {
763-
return this._isReady;
763+
return this._pendingReadyPromise === 0;
764764
}
765765

766766
/**
@@ -787,7 +787,7 @@ export class GitExtension implements IGitExtension, IDisposable {
787787
private _diffProviders: { [key: string]: Git.IDiffCallback } = {};
788788
private _isDisposed = false;
789789
private _readyPromise: Promise<void> = Promise.resolve();
790-
private _isReady = true;
790+
private _pendingReadyPromise = 0;
791791
private _poll: Poll;
792792
private _headChanged = new Signal<IGitExtension, void>(this);
793793
private _repositoryChanged = new Signal<

src/tokens.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,16 @@ export interface IGitExtension {
180180
*/
181181
init(path: string): Promise<Response>;
182182

183+
/**
184+
* Gets the path of the file relative to the Jupyter server root.
185+
*
186+
* If no path is provided, returns the Git repository top folder relative path.
187+
* If no Git repository selected, return null
188+
*
189+
* @param path the file path relative to Git repository top folder
190+
*/
191+
getRelativeFilePath(path?: string): string | null;
192+
183193
/**
184194
* Register a new diff provider for specified file types
185195
*

0 commit comments

Comments
 (0)