Skip to content

Commit

Permalink
Test if nbgitpuller extension is installed (#20)
Browse files Browse the repository at this point in the history
* Test nbgitpuller API to make sure it is not installed

* Test that litegitpuller is not activated if nbgitpuller is installed

* lint

* Test the endpoint without settings

Co-authored-by: Jeremy Tuloup <[email protected]>

* Use matrix in the tests

* Fix ui test

---------

Co-authored-by: Jeremy Tuloup <[email protected]>
  • Loading branch information
brichet and jtpio authored Jul 24, 2024
1 parent 70d6240 commit f83164e
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 9 deletions.
11 changes: 9 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ jobs:
name: Integration tests
needs: build
runs-on: ubuntu-latest
strategy:
matrix:
project: [general, nbgitpuller]

env:
PLAYWRIGHT_BROWSERS_PATH: ${{ github.workspace }}/pw-browsers
Expand All @@ -102,6 +105,10 @@ jobs:
with:
name: extension-artifacts

- name: Install nbgitpuller
if: ${{ matrix.project == 'nbgitpuller' }}
run: pip install nbgitpuller

- name: Install the extension
run: |
set -eux
Expand All @@ -128,13 +135,13 @@ jobs:
- name: Execute integration tests
working-directory: ui-tests
run: |
jlpm playwright test
jlpm playwright test --project ${{ matrix.project }}
- name: Upload Playwright Test report
if: always()
uses: actions/upload-artifact@v3
with:
name: litegitpuller-playwright-tests
name: litegitpuller-ui-tests_${{ matrix.project }}
path: |
ui-tests/test-results
ui-tests/playwright-report
Expand Down
44 changes: 39 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,55 @@ import {
JupyterFrontEnd,
JupyterFrontEndPlugin
} from '@jupyterlab/application';
import { PathExt } from '@jupyterlab/coreutils';
import { PathExt, URLExt } from '@jupyterlab/coreutils';
import { IDefaultFileBrowser } from '@jupyterlab/filebrowser';
import { ServerConnection } from '@jupyterlab/services';
import { GitPuller, GithubPuller, GitlabPuller } from './gitpuller';

/**
* Test if nbgitpuller extension is also installed by requesting its Rest API.
* This test avoid fetching the same repository two times.
*/
export async function testNbGitPuller(): Promise<boolean> {
// Make request to Jupyter API
const settings = ServerConnection.makeSettings();
const requestUrl = URLExt.join(settings.baseUrl, 'git-pull', 'api');
let response: Response;
try {
response = await ServerConnection.makeRequest(
requestUrl,
{ method: 'GET' },
settings
);
} catch (error) {
return false;
}

if (!response.ok) {
return false;
}

return true;
}

const gitPullerExtension: JupyterFrontEndPlugin<void> = {
id: '@jupyterlite/litegitpuller:plugin',
autoStart: true,
requires: [IDefaultFileBrowser],
activate: (app: JupyterFrontEnd, defaultFileBrowser: IDefaultFileBrowser) => {
activate: async (
app: JupyterFrontEnd,
defaultFileBrowser: IDefaultFileBrowser
) => {
if (await testNbGitPuller()) {
console.log(
'@jupyterlite/litegitpuller is not activated, to avoid conflict with nbgitpuller'
);
return;
}

console.log(
'JupyterLab extension @jupyterlite/litegitpuller is activated!'
);
if (!(app.name === 'JupyterLite')) {
return;
}

const urlParams = new URLSearchParams(window.location.search);
const repo = urlParams.get('repo');
Expand Down
29 changes: 29 additions & 0 deletions ui-tests/nbgitpuller_test/test.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { expect, test } from '@jupyterlab/galata';

/**
* ### NOTE:
* This test is supposed to run with nbgitpuller extension installed, to make
* sure that the litegitpuller extension is not activated in that case.
*/

//Don't load JupyterLab webpage before running the tests.
//This is required to ensure we capture all log messages.
test.use({ autoGoto: false });

test('should emit a non activation console message', async ({ page }) => {
const logs: string[] = [];

page.on('console', message => {
logs.push(message.text());
});

await page.goto();

expect(
logs.filter(
s =>
s ===
'@jupyterlite/litegitpuller is not activated, to avoid conflict with nbgitpuller'
)
).toHaveLength(1);
});
3 changes: 2 additions & 1 deletion ui-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"private": true,
"scripts": {
"start": "jupyter lab --config jupyter_server_test_config.py",
"test": "jlpm playwright test",
"test": "jlpm playwright test --project general",
"test:nbgitpuller": "jlpm playwright test --project nbgitpuller",
"test:update": "jlpm playwright test --update-snapshots"
},
"devDependencies": {
Expand Down
12 changes: 11 additions & 1 deletion ui-tests/playwright.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,15 @@ module.exports = {
url: 'http://localhost:8888/lab',
timeout: 120 * 1000,
reuseExistingServer: !process.env.CI
}
},
projects: [
{
name: 'general',
testMatch: 'tests/*.spec.ts'
},
{
name: 'nbgitpuller',
testMatch: 'nbgitpuller_test/*.spec.ts'
}
]
};

0 comments on commit f83164e

Please sign in to comment.