This repository has been archived by the owner on Aug 8, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #42 from jupyterlab/testing
Add tests
- Loading branch information
Showing
11 changed files
with
276 additions
and
7 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
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,26 @@ | ||
on: [push, pull_request] | ||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v1 | ||
- uses: actions/setup-python@v1 | ||
with: | ||
python-version: "3.6" | ||
- uses: actions/setup-node@v1 | ||
with: | ||
node-version: "10.x" | ||
- run: python -m pip install --upgrade pip | ||
- run: pip install jupyterlab | ||
- run: jlpm run build | ||
- run: jupyter labextension install . @jupyterlab/dataregistry-extension --debug-log-path log.txt | ||
- if: failure() | ||
run: cat log.txt | ||
- run: jlpm run test | ||
- name: upload screenshots | ||
if: failure() | ||
uses: actions/upload-artifact@v1 | ||
with: | ||
name: screenshots | ||
path: screenshots |
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 |
---|---|---|
|
@@ -118,3 +118,4 @@ node_modules/ | |
# npm | ||
yarn.lock | ||
package-lock.json | ||
screenshots |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/** | ||
* @license BSD-3-Clause | ||
* | ||
* Copyright (c) 2019 Project Jupyter Contributors. | ||
* Distributed under the terms of the 3-Clause BSD License. | ||
*/ | ||
|
||
// Based on from https://yarnpkg.com/en/package/@rws-air/jestscreenshot | ||
|
||
const PuppeteerEnvironment = require('jest-environment-puppeteer'); | ||
const JestScreenshot = require('@rws-air/jestscreenshot'); | ||
|
||
class CustomEnvironment extends PuppeteerEnvironment { | ||
async setup() { | ||
await super.setup(); | ||
} | ||
async teardown() { | ||
await this.global.page.waitFor(2000); | ||
await super.teardown(); | ||
} | ||
|
||
async handleTestEvent(event, state) { | ||
if (event.name === 'test_fn_failure') { | ||
const testName = state.currentlyRunningTest.name; | ||
|
||
const jestScreenshot = new JestScreenshot({ | ||
page: this.global.page, | ||
dirName: __dirname, | ||
testName | ||
}); | ||
|
||
await jestScreenshot.setup(); | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Exports. | ||
*/ | ||
module.exports = CustomEnvironment; |
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,23 @@ | ||
/** | ||
* @license BSD-3-Clause | ||
* | ||
* Copyright (c) 2019 Project Jupyter Contributors. | ||
* Distributed under the terms of the 3-Clause BSD License. | ||
*/ | ||
|
||
const config = { | ||
launch: { | ||
headless: process.env.HEADLESS !== 'false', | ||
slowMo: process.env.SLOWMO === 'true' | ||
}, | ||
// https://github.com/smooth-code/jest-puppeteer/tree/master/packages/jest-dev-server#options | ||
server: { | ||
command: "jupyter lab --port 8080 --no-browser --LabApp.token=''", | ||
port: 8080 | ||
} | ||
}; | ||
|
||
/** | ||
* Exports. | ||
*/ | ||
module.exports = config; |
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,36 @@ | ||
/** | ||
* @license BSD-3-Clause | ||
* | ||
* Copyright (c) 2019 Project Jupyter Contributors. | ||
* Distributed under the terms of the 3-Clause BSD License. | ||
*/ | ||
|
||
const { defaults: tsjPreset } = require('ts-jest/presets'); | ||
|
||
const config = { | ||
rootDir: '.', | ||
|
||
// Needed for jest-screenshots | ||
testRunner: 'jest-circus/runner', | ||
|
||
testEnvironment: './jest-environment.js', | ||
globalSetup: 'jest-environment-puppeteer/setup', | ||
globalTeardown: 'jest-environment-puppeteer/teardown', | ||
setupFilesAfterEnv: ['expect-puppeteer'], | ||
transform: { | ||
...tsjPreset.transform | ||
}, | ||
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'], | ||
testMatch: ['**/test/**/test*.ts?(x)'], | ||
testPathIgnorePatterns: ['/build/', '/lib/', '/node_modules/'], | ||
globals: { | ||
'ts-jest': { | ||
tsConfig: './tsconfig.test.json' | ||
} | ||
} | ||
}; | ||
|
||
/** | ||
* Exports. | ||
*/ | ||
module.exports = config; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
/** | ||
* @license BSD-3-Clause | ||
* | ||
* Copyright (c) 2019 Project Jupyter Contributors. | ||
* Distributed under the terms of the 3-Clause BSD License. | ||
*/ | ||
|
||
import { ElementHandle } from 'puppeteer'; | ||
|
||
const { setDefaultOptions } = require('expect-puppeteer'); | ||
|
||
const timeout = 15 * 1000; | ||
|
||
jest.setTimeout(timeout); | ||
setDefaultOptions({ timeout }); | ||
|
||
async function getXPath(xpath: string): Promise<ElementHandle<Element>> { | ||
await page.waitForXPath(xpath); | ||
const elements = await page.$x(xpath); | ||
expect(elements.length).toBe(1); | ||
return elements[0]; | ||
} | ||
|
||
function sleep(ms: number): Promise<void> { | ||
return new Promise(resolve => setTimeout(resolve, ms)); | ||
} | ||
describe('JupyterLab', () => { | ||
beforeAll(async () => { | ||
// Load JupyterLab: | ||
await page.goto('http://localhost:8080/lab?reset'); | ||
|
||
// NOTE: depending on system resource constraints, this may NOT be enough time for JupyterLab to load and get "settled", so to speak. If CI tests begin inexplicably failing due to timeout failures, may want to consider increasing the sleep duration... | ||
await sleep(3000); | ||
|
||
// Attempt to find the data explorer tab on the page (all tests essentially presume that we can load the data explorer via the tab bar button): | ||
const el = await page.$('[title="Data Explorer"]'); | ||
if (el !== null) { | ||
// Clicking on the data explorer tab should open the data explorer, thus allowing us to test data explorer UI interactions: | ||
el.click(); | ||
} else { | ||
console.log('Unable to find expected tab.'); | ||
} | ||
}); | ||
|
||
it('should show JupyterLab logo', async () => { | ||
expect.assertions(1); | ||
await expect(page).toMatchElement('#jp-MainLogo', { visible: true } as any); | ||
}); | ||
|
||
it("show be able to show 'Data Explorer' tab", async () => { | ||
expect.assertions(1); | ||
await expect(page).toMatchElement('.jl-explorer-heading', { | ||
text: 'Datasets', | ||
visible: true | ||
} as any); | ||
}); | ||
|
||
it('should see files marker', async () => { | ||
expect.assertions(1); | ||
await expect(page).toMatchElement('h3', { | ||
text: 'file:///', | ||
visible: true | ||
} as any); | ||
}); | ||
|
||
it('should be able to expand files', async () => { | ||
expect.assertions(1); | ||
const filebutton = await getXPath('//button[../h3/text()="file:///"]'); | ||
await filebutton.click(); | ||
}); | ||
|
||
it('should see datasets.yml marker', async () => { | ||
expect.assertions(1); | ||
await expect(page).toMatchElement('h3', { | ||
text: 'datasets.yml', | ||
visible: true | ||
} as any); | ||
}); | ||
|
||
it('should be able to expand datasets.yml', async () => { | ||
expect.assertions(1); | ||
const datasetsButton = await getXPath( | ||
'//button[../h3/text()="datasets.yml"]' | ||
); | ||
await datasetsButton.click(); | ||
}); | ||
|
||
it('should show datasets label', async () => { | ||
expect.assertions(1); | ||
await expect(page).toMatchElement('h3', { | ||
text: 'A Publication', | ||
visible: true | ||
} as any); | ||
}); | ||
|
||
it("show be able to show 'Data Browser' tab", async () => { | ||
expect.assertions(2); | ||
await expect(page).toClick('[title="Data Browser"]'); | ||
await expect(page).toMatchElement('.jl-dr-browser', { | ||
text: 'Follow active?', | ||
visible: true | ||
} as any); | ||
}); | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"extends": "./tsconfig.json", | ||
"compilerOptions": { | ||
"outDir": "build/test", | ||
"rootDir": "test" | ||
}, | ||
"include": ["test/*", "test/**/*"] | ||
} |