Skip to content
This repository was archived by the owner on Jan 12, 2024. It is now read-only.

Commit 6e94059

Browse files
fix: update service worker test to use playwright (#33)
* fix: update test to use playwright * fix: add retry
1 parent b461ec5 commit 6e94059

File tree

15 files changed

+490
-644
lines changed

15 files changed

+490
-644
lines changed
Lines changed: 114 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,80 @@
1-
# Using js-ipfs node in [SharedWorker][] from [ServiceWorker][]
1+
<p align="center">
2+
<a href="https://js.ipfs.io" title="JS IPFS">
3+
<img src="https://ipfs.io/ipfs/Qme6KJdKcp85TYbLxuLV7oQzMiLremD7HMoXLZEmgo6Rnh/js-ipfs-sticker.png" alt="IPFS in JavaScript logo" width="244" />
4+
</a>
5+
</p>
6+
7+
<h3 align="center"><b>js-ipfs node using web workers</b></h3>
8+
9+
<p align="center">
10+
<b><i>Using js-ipfs node in [SharedWorker][] from [ServiceWorker][]</i></b>
11+
<br />
12+
<br />
13+
<img src="https://raw.githubusercontent.com/jlord/forkngo/gh-pages/badges/cobalt.png" width="200">
14+
<br>
15+
<a href="https://github.com/ipfs/js-ipfs/tree/master/docs">Explore the docs</a>
16+
·
17+
<a href="https://codesandbox.io/">View Demo</a>
18+
·
19+
<a href="https://github.com/ipfs-examples/js-ipfs-examples/issues">Report Bug</a>
20+
·
21+
<a href="https://github.com/ipfs-examples/js-ipfs-examples/issues">Request Feature/Example</a>
22+
</p>
23+
24+
## Table of Contents
25+
26+
- [Table of Contents](#table-of-contents)
27+
- [About The Project](#about-the-project)
28+
- [Getting Started](#getting-started)
29+
- [Prerequisites](#prerequisites)
30+
- [Installation and Running example](#installation-and-running-example)
31+
- [Usage](#usage)
32+
- [General Overview](#general-overview)
33+
- [`src/main.js`](#srcmainjs)
34+
- [`src/worker.js`](#srcworkerjs)
35+
- [`src/service.js`](#srcservicejs)
36+
- [Running example](#running-example)
37+
- [Documentation](#documentation)
38+
- [Contributing](#contributing)
39+
- [Want to hack on IPFS?](#want-to-hack-on-ipfs)
40+
41+
## About The Project
42+
43+
- Read the [docs](https://github.com/ipfs/js-ipfs/tree/master/docs)
44+
- Look into other [examples](https://github.com/ipfs-examples/js-ipfs-examples) to learn how to spawn an IPFS node in Node.js and in the Browser
45+
- Consult the [Core API docs](https://github.com/ipfs/js-ipfs/tree/master/docs/core-api) to see what you can do with an IPFS node
46+
- Visit https://dweb-primer.ipfs.io to learn about IPFS and the concepts that underpin it
47+
- Head over to https://proto.school to take interactive tutorials that cover core IPFS APIs
48+
- Check out https://docs.ipfs.io for tips, how-tos and more
49+
- See https://blog.ipfs.io for news and more
50+
- Need help? Please ask 'How do I?' questions on https://discuss.ipfs.io
51+
52+
## Getting Started
53+
54+
### Prerequisites
55+
56+
Make sure you have installed all of the following prerequisites on your development machine:
57+
58+
- Git - [Download & Install Git](https://git-scm.com/downloads). OSX and Linux machines typically have this already installed.
59+
- Node.js - [Download & Install Node.js](https://nodejs.org/en/download/) and the npm package manager.
60+
61+
### Installation and Running example
62+
63+
```console
64+
> npm install
65+
> npm start
66+
```
67+
68+
Now open your browser at `http://localhost:3000`
69+
70+
## Usage
271

372
> In this example, you will find boilerplate code you can use to set up an IPFS
473
> node in a [SharedWorker][] and use it from a [ServiceWorker][].
574
6-
## General Overview
75+
### General Overview
776

8-
### `src/main.js`
77+
#### `src/main.js`
978

1079
Module is loaded in the main thread (DOM window) and is responsible for wiring
1180
all the pieces together:
@@ -16,12 +85,12 @@ all the pieces together:
1685
back with a [MessagePort][] of the [SharedWorker][], enabling
1786
it to interact with shaerd IPFS node.
1887

19-
### `src/worker.js`
88+
#### `src/worker.js`
2089

2190
Module is loaded in the [SharedWorker][]. It demonstrates how to setup the IPFS
2291
node such that it can be used in other browsing contexts.
2392

24-
### `src/service.js`
93+
#### `src/service.js`
2594

2695
Module is loaded in the [ServiceWorker][] and responds to all the requests from
2796
the page. It recognizes four different request routes:
@@ -34,7 +103,7 @@ the page. It recognizes four different request routes:
34103
/ipfs/Qm...hash/file/name -> /view/Qm...hash/file/name
35104
```
36105
- `src/main.js` script loaded in it.
37-
106+
38107
This way when request from `/view/Qm..hash/file/name` arrives [ServiceWorker][]
39108
can obtain a [MessagePort][] for the [SharedWorker][] by requesting it from
40109
the iframe container.
@@ -45,48 +114,60 @@ the page. It recognizes four different request routes:
45114
[MessagePort][] for the [SharedWorker][] is obtained and used to retrieve
46115
content from the shared IPFS node and served back.
47116

48-
> There is a stub for `/view/ipns/...` route, which is left as an excercise
117+
> There is a stub for `/view/ipns/...` route, which is left as an exercise
49118
> for the reader to fill.
50119
51-
3. All other routes are served by fetchging it from the network.
120+
3. All other routes are served by fetching it from the network.
52121

122+
### Running example
53123

54-
## Before you start
124+
You should see the following:
55125

56-
First clone this repo, cd into the example directory and install the dependencies
126+
![Screen Shot](./img/index-view.png)
57127

58-
```bash
59-
git clone https://github.com/ipfs/js-ipfs.git
60-
cd js-ipfs/examples/browser-service-worker
61-
npm install
62-
```
128+
If you navigate to the following address `http://localhost:3000/ipfs/bafybeicqzoixu6ivztffjy4bktwxy6lxaxkvnavkya7kfgwyhx4bund2ga/` it should load a
129+
page from ipfs and appear as:
63130

64-
## Running the example
131+
![Screen Shot](./img/page-view.png)
65132

66-
Run the following command within this folder:
67133

68-
```bash
69-
npm start
70-
```
134+
[SharedWorker]:https://developer.mozilla.org/en-US/docs/Web/API/SharedWorker
135+
[ServiceWorker]:https://developer.mozilla.org/en-US/docs/Web/API/Service_Worker_API
136+
[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort
71137

72-
Now open your browser at `http://localhost:3000`
138+
_For more examples, please refer to the [Documentation](#documentation)_
73139

74-
You should see the following:
140+
## Documentation
75141

76-
![Screen Shot](./index-view.png)
142+
- [Config](https://docs.ipfs.io/)
143+
- [Core API](https://github.com/ipfs/js-ipfs/tree/master/docs/core-api)
144+
- [Examples](https://github.com/ipfs-examples/js-ipfs-examples)
145+
- [Development](https://github.com/ipfs/js-ipfs/blob/master/docs/DEVELOPMENT.md)
146+
- [Tutorials](https://proto.school)
77147

78-
If you navigate to the following address `http://localhost:3000/ipfs/bafybeicqzoixu6ivztffjy4bktwxy6lxaxkvnavkya7kfgwyhx4bund2ga/` it should load a
79-
page from ipfs and appear as:
148+
## Contributing
80149

81-
![Screen Shot](./page-view.png)
150+
Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are **greatly appreciated**.
82151

83-
### Run tests
152+
1. Fork the IPFS Project
153+
2. Create your Feature Branch (`git checkout -b feature/amazing-feature`)
154+
3. Commit your Changes (`git commit -a -m 'feat: add some amazing feature'`)
155+
4. Push to the Branch (`git push origin feature/amazing-feature`)
156+
5. Open a Pull Request
84157

85-
```bash
86-
npm test
87-
```
158+
## Want to hack on IPFS?
88159

160+
[![](https://cdn.rawgit.com/jbenet/contribute-ipfs-gif/master/img/contribute.gif)](https://github.com/ipfs/community/blob/master/CONTRIBUTING.md)
89161

90-
[SharedWorker]:https://developer.mozilla.org/en-US/docs/Web/API/SharedWorker
91-
[ServiceWorker]:https://developer.mozilla.org/en-US/docs/Web/API/Service_Worker_API
92-
[MessagePort]:https://developer.mozilla.org/en-US/docs/Web/API/MessagePort
162+
The IPFS implementation in JavaScript needs your help! There are a few things you can do right now to help out:
163+
164+
Read the [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md) and [JavaScript Contributing Guidelines](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md).
165+
166+
- **Check out existing issues** The [issue list](https://github.com/ipfs/js-ipfs/issues) has many that are marked as ['help wanted'](https://github.com/ipfs/js-ipfs/issues?q=is%3Aissue+is%3Aopen+sort%3Aupdated-desc+label%3A%22help+wanted%22) or ['difficulty:easy'](https://github.com/ipfs/js-ipfs/issues?q=is%3Aissue+is%3Aopen+sort%3Aupdated-desc+label%3Adifficulty%3Aeasy) which make great starting points for development, many of which can be tackled with no prior IPFS knowledge
167+
- **Look at the [IPFS Roadmap](https://github.com/ipfs/roadmap)** This are the high priority items being worked on right now
168+
- **Perform code reviews** More eyes will help
169+
a. speed the project along
170+
b. ensure quality, and
171+
c. reduce possible future bugs.
172+
- **Add tests**. There can never be enough tests.
173+
- **Join the [Weekly Core Implementations Call](https://github.com/ipfs/team-mgmt/issues/992)** it's where everyone discusses what's going on with IPFS and what's next

examples/browser-service-worker/index.html

Lines changed: 0 additions & 119 deletions
This file was deleted.

examples/browser-service-worker/package.json

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,15 @@
66
"keywords": [],
77
"license": "MIT",
88
"scripts": {
9-
"clean": "rm -rf ./dist",
10-
"build": "webpack",
11-
"start": "webpack-dev-server",
12-
"test": "test-ipfs-example"
9+
"clean": "rimraf ./dist",
10+
"build": "webpack --env production",
11+
"serve": "webpack serve --hot-only --mode=development",
12+
"start": "npm run serve",
13+
"test": "npm run build && playwright test tests"
1314
},
15+
"browserslist": [
16+
"last 1 Chrome version"
17+
],
1418
"dependencies": {
1519
"ipfs": "^0.58.1",
1620
"ipfs-message-port-client": "^0.8.3",
@@ -21,11 +25,20 @@
2125
"devDependencies": {
2226
"@babel/core": "^7.13.10",
2327
"@babel/preset-env": "^7.13.12",
28+
"@playwright/test": "^1.12.3",
2429
"babel-loader": "^8.2.2",
2530
"copy-webpack-plugin": "^9.0.1",
26-
"test-ipfs-example": "^3.0.0",
27-
"webpack": "^5.28.0",
28-
"webpack-cli": "^4.5.0",
29-
"webpack-dev-server": "^3.11.2"
31+
"css-loader": "^6.2.0",
32+
"html-webpack-plugin": "^5.3.2",
33+
"node-polyfill-webpack-plugin": "^1.0.4",
34+
"playwright": "^1.12.3",
35+
"rimraf": "^3.0.2",
36+
"stream-browserify": "^3.0.0",
37+
"style-loader": "^3.1.0",
38+
"test-util-ipfs-example": "^1.0.2",
39+
"webpack": "^5.45.1",
40+
"webpack-cli": "^4.7.2",
41+
"webpack-dev-server": "^3.11.2",
42+
"webpack-merge": "^5.8.0"
3043
}
3144
}
Binary file not shown.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
7+
8+
<title><%= htmlWebpackPlugin.options.title %></title>
9+
</head>
10+
<body>
11+
<article class="vh-100 dt w-100">
12+
<div class="dtc v-mid tc ph3 ph4-l">
13+
<h1 class="f6 f2-m f-subheadline-l fw6 tc">Load content by adding IPFS path to the URL ⤴</h2>
14+
<p>Something like <a
15+
href="/ipfs/bafybeicqzoixu6ivztffjy4bktwxy6lxaxkvnavkya7kfgwyhx4bund2ga/">/ipfs/bafybeicqzoixu6ivztffjy4bktwxy6lxaxkvnavkya7kfgwyhx4bund2ga/</a>
16+
</p>
17+
<p id=debug></p>
18+
</div>
19+
</article>
20+
</body>
21+
</html>

0 commit comments

Comments
 (0)