Skip to content

Commit

Permalink
Add prettier and format all files. (#3)
Browse files Browse the repository at this point in the history
Adds a `fix` command and includes
prettier in the `test` command.
  • Loading branch information
blois authored Sep 2, 2021
1 parent 95a9324 commit b827888
Show file tree
Hide file tree
Showing 26 changed files with 2,308 additions and 2,212 deletions.
11 changes: 3 additions & 8 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,6 @@
module.exports = {
root: true,
parser: '@typescript-eslint/parser',
plugins: [
'@typescript-eslint',
],
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
],
};
plugins: ['@typescript-eslint'],
extends: ['eslint:recommended', 'plugin:@typescript-eslint/recommended'],
};
3 changes: 3 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules/
dist/
lib/
4 changes: 4 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"bracketSpacing": false,
"singleQuote": true
}
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ information on using pull requests.
## Community Guidelines

This project follows
[Google's Open Source Community Guidelines](https://opensource.google/conduct/).
[Google's Open Source Community Guidelines](https://opensource.google/conduct/).
16 changes: 9 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@ implementation to allow users to arbitrary widgets from arbitrary sources.
This project includes an implementation of a widget manager which loads widgets from a
CDN.


## Pluggable Widget Manager API

Colab frontend should expose an API for users to specify what widget manager
they would like to use.

The API should be as minimal as possible and avoid being tied to specific Jupyter Widgers versions. The notebook author should have the flexibility to determine the Jupyter Widgets version they would like to use. Later viewers of the notebook will see the widgets rendered with the same Jupyter Widgets version as the original author.


#### API Proposal

Expose a global method for registering a custom widget manager:
Expand All @@ -24,13 +23,14 @@ google.colab.widgets.installCustomManager(url: string, args: any): void

This API can be invoked at any point by Javascript outputs to change the widget manager for all subsequent outputs. This API can be wrapped in a Python API to make it easier to invoke from a kernel.


The URL must resolve to an ES6 module exporting the WidgetManagerModule interface:

```typescript
interface WidgetManagerModule {
createWidgetManager(state: WidgetEnvironment, arguments?: unknown):
IWidgetManager;
createWidgetManager(
state: WidgetEnvironment,
arguments?: unknown
): IWidgetManager;
}

interface IWidgetManager {
Expand All @@ -40,14 +40,14 @@ interface IWidgetManager {

After a custom widget manager has been registered and a Jupyter Widget is being rendered to the outputs then the custom widget manager module will be loaded, the widget manager will be created and all widgets within that window will be created with that manager.


Once a custom widget manager has been registered then a manager will be instantiated when any widgets need to be rendered in the notebook.

The full API details are included in Colab's [outputframe declaration file](https://github.com/googlecolab/colabtools/blob/07b38dfa2869780ff2128cf7c1ad4414d1b4109c/packages/outputframe/lib/index.d.ts#L154-L210).
The full API details are included in Colab's [outputframe declaration file](https://github.com/googlecolab/colabtools/blob/07b38dfa2869780ff2128cf7c1ad4414d1b4109c/packages/outputframe/lib/index.d.ts#L154-L210).

# Development

Install and run the development server:

```shell
npm install
npm run server
Expand Down Expand Up @@ -78,7 +78,9 @@ npm run tests
```

Alternatively functional tests can be executed and debugged with:

```
npm run test:karma:dev
```

Then navigate to http://localhost:9876/.
2 changes: 1 addition & 1 deletion build.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@ const esbuild = require('esbuild');
format: 'esm',
minify: true,
});
})();
})();
4 changes: 2 additions & 2 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
module.exports = {
roots: ['./src'],
transform: {
"^.+\\.tsx?$": "esbuild-jest",
'^.+\\.tsx?$': 'esbuild-jest',
},
testRegex: '(/__tests__/.*|(\\.|/)(test|spec))\\.tsx?$',
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
testEnvironment: 'jsdom',
}
};
38 changes: 14 additions & 24 deletions karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,72 +15,62 @@
* limitations under the License.
*/

module.exports = function(config) {
module.exports = function (config) {
config.set({

// base path that will be used to resolve all patterns (eg. files, exclude)
basePath: '',


// frameworks to use
// available frameworks: https://www.npmjs.com/search?q=keywords:karma-adapter
frameworks: ['jasmine'],


// list of files / patterns to load in the browser
files: [
{pattern: "dist/manager.dev.js", included: false, served: true, type: "module"},
{pattern: "test/**/*.js", type: "module", included: true},
{pattern: "test/**/*.json", included: false, served: true},
{
pattern: 'dist/manager.dev.js',
included: false,
served: true,
type: 'module',
},
{pattern: 'test/**/*.js', type: 'module', included: true},
{pattern: 'test/**/*.json', included: false, served: true},
],


// list of files / patterns to exclude
exclude: [
'test/server/**',
],

exclude: ['test/server/**'],

// preprocess matching files before serving them to the browser
// available preprocessors: https://www.npmjs.com/search?q=keywords:karma-preprocessor
preprocessors: {
},

preprocessors: {},

// test results reporter to use
// possible values: 'dots', 'progress'
// available reporters: https://www.npmjs.com/search?q=keywords:karma-reporter
reporters: ['dots', 'progress', 'kjhtml'],


// web server port
port: 9876,


// enable / disable colors in the output (reporters and logs)
colors: true,


// level of logging
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
logLevel: config.LOG_INFO,


// enable / disable watching file and executing tests whenever any file changes
autoWatch: true,


// start these browsers
// available browser launchers: https://www.npmjs.com/search?q=keywords:karma-launcher
browsers: ['ChromeHeadless'],


// Continuous Integration mode
// if true, Karma captures browsers, runs the tests and exits
singleRun: false,

// Concurrency level
// how many browser instances should be started simultaneously
concurrency: Infinity
})
}
concurrency: Infinity,
});
};
111 changes: 111 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,21 @@
"clean": "rimraf dist && rimraf lib",
"compile:test": "tsc -p test/server",
"compile": "tsc",
"fix": "npx prettier --write .",
"lint": "node node_modules/eslint/bin/eslint.js src --ext .js,.jsx,.ts,.tsx",
"prepare": "npm run clean && npm run build",
"server": "npm run compile:test && node test/server/lib/server.js",
"test:jest": "node node_modules/.bin/jest",
"test:karma:dev": "./node_modules/karma/bin/karma start karma.conf.js",
"test:karma": "npm run build && ./node_modules/karma/bin/karma start karma.conf.js --single-run",
"test": "npm run test:jest && npm run test:karma"
"test:prettier": "npx prettier --check .",
"test": "npm run test:jest && npm run test:karma && npm run test:prettier"
},
"devDependencies": {
"@jupyter-widgets/base": "^5.0.0-alpha.3",
"@jupyter-widgets/base-manager": "1.0.0-alpha.2",
"@jupyter-widgets/controls": "^4.0.0-alpha.3",
"@trivago/prettier-plugin-sort-imports": "^2.0.4",
"@types/jest": "^26.0.24",
"@types/mocha": "^9.0.0",
"@types/node": "^14.14.10",
Expand All @@ -43,6 +46,7 @@
"karma-jasmine-html-reporter": "^1.7.0",
"karma-typescript": "^5.5.1",
"mocha": "^9.0.3",
"prettier": "^2.3.2",
"rimraf": "^2.6.1",
"ts-jest": "^27.0.4",
"tslint": "^5.8.0",
Expand Down
18 changes: 12 additions & 6 deletions src/amd.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,20 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { expect } from '@jest/globals';
import {Loader} from './amd';
import {expect} from '@jest/globals';

test('getHostedModuleUrl', () => {
const loader = new Loader();
expect(loader.resolveModule('foo').pathname).toBe('/npm/foo@*/dist/index.js');
expect(loader.resolveModule('@jupyter-widgets/base').pathname).toBe('/npm/@jupyter-widgets/base@*/dist/index.js');
expect(loader.resolveModule('@jupyter-widgets/base', '4.0.0').pathname).toBe('/npm/@jupyter-widgets/[email protected]/dist/index.js');
expect(loader.resolveModule('@jupyter-widgets/base/css/index.css', '4.0.0').pathname).toBe('/npm/@jupyter-widgets/[email protected]/css/index.css');
});
expect(loader.resolveModule('@jupyter-widgets/base').pathname).toBe(
'/npm/@jupyter-widgets/base@*/dist/index.js'
);
expect(loader.resolveModule('@jupyter-widgets/base', '4.0.0').pathname).toBe(
'/npm/@jupyter-widgets/[email protected]/dist/index.js'
);
expect(
loader.resolveModule('@jupyter-widgets/base/css/index.css', '4.0.0')
.pathname
).toBe('/npm/@jupyter-widgets/[email protected]/css/index.css');
});
Loading

0 comments on commit b827888

Please sign in to comment.