Comments (5)
One implementation is now partially done in https://github.com/kinow/cylc-web/tree/add-services. Now need to try to write a unit test.
If we are able to test everything, except the HTTP call (mocked), then I think this is a good starting point for future services used to talk to suite list service, other parts of the hub like proxy API, etc.
from cylc-ui.
Writing the unit test was quite easy and simple. The plan was to see the test failing, and use Sinon.JS to mock the call.
However, faced a different issue as importing the services, apparently webpack imported the classes with GraphQL. And there is a known issue that running the Apollo GraphQL client in the node environment (i.e. without a browser), it fails due to the missing fetch
.
If you open a browser window, then go to any URL, open the developer tools, and type in the Console: window.fetch
, you will see that the browser defines it. But when browserless (as when running the unit tests), that variables does not exist.
This was fixed in Apollo apollographql/apollo-client#3578, and there is now a way to pass a fetch
object.
from cylc-ui.
I've moved the GraphQL call from Vuex to its own service anyway, and thought that maybe we could fix this issue later. But in someway the module is still loaded, and the whole tests fail with
WEBPACK Compiled successfully in 3852ms
MOCHA Testing...
RUNTIME EXCEPTION Exception occurred while loading your tests
Error:
fetch is not found globally and no fetcher passed, to fix pass a fetch for
your environment like https://www.npmjs.com/package/unfetch.
For example:
import fetch from 'unfetch';
import { createHttpLink } from 'apollo-link-http';
...
ERROR mocha-webpack exited with code 1.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] test:unit: `vue-cli-service test:unit`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] test:unit script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /home/kinow/.npm/_logs/2019-02-27T21_42_45_483Z-debug.log
So now gotta find a way to pass a fetch object before each test. But in a way that is simpler... because just asking developers to copy and paste a block of code for each test is not quite good.
from cylc-ui.
Tried a root-level hook for Mocha, but even that way the error appears to occur before Mocha loads the hook.
The only way to fix it was using node-fetch
.
// import { createProvider } from './vue-apollo'
import ApolloClient from 'apollo-boost'
import fetch from 'node-fetch'
// GraphQL
const apolloClient = new ApolloClient({
// You should use an absolute URL here
uri: "https://api.graphcms.com/simple/v1/awesomeTalksClone",
// we must define fetch, as otherwise running unit tests it would fail as there is no global fetch variable
fetch: fetch
});
export default apolloClient
Though that introduced a warning when running unit tests 😥
Warning in ./node_modules/node-fetch/lib/index.mjs
Module not found: 'encoding' in '/home/kinow/Development/python/workspace/cylc-web/node_modules/node-fetch/lib'
Npm node-fetch documentation says:
(This API requires an optional dependency on npm package encoding, which you need to install manually. webpack users may see a warning message due to this optional dependency.)
As it appears to work fine, leaving it for now to prevent increasing our final produced HTML/JS/CSS, etc.
from cylc-ui.
Done! We have services! And we are retrieving the User profile from the service. And this user service is retrieving the data from JupyterHub! Phew! That was quite a long ride to get the data from the hub 😪
from cylc-ui.
Related Issues (20)
- tree: don't expand all cycles if the resulting node count is too high
- data store: change data structure
- table: tasks disappear HOT 9
- table: task state unknown HOT 3
- Differing sort order in menu before and after "SEE MORE" is clicked HOT 3
- Replace 'Run time' with 'Expected Run Time' and include 'Actual Run Time' in web UI Table view? HOT 1
- Make cylc hold more visible HOT 8
- Minor cosmetic bug - menu doesn't disappear when a form opens HOT 1
- Menu button and forms - what should be happening? HOT 2
- filtering: consider task modifier filtering
- log: log view contents is duplicated on reconnect
- Hover text over nodes for basic summary information HOT 1
- Filter by ID handle globs or regex? HOT 1
- Couple of Gantt view improvements
- Gantt view: live updates or refresh button
- Keyboard focus should go to newly opened tab HOT 1
- graph: clear the graph when there is nothing to draw
- Warning: fragment with name X already exists HOT 1
- Analysis time series view: long task names clutter up dropdown
- task: progress animation resets on tab change
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cylc-ui.