Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(progess): emit progress-update #2498

Merged
merged 1 commit into from
Apr 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/Server.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,10 @@ class Server {
}

this.sockWrite(this.sockets, 'progress-update', { percent, msg });

if (this.listeningApp) {
this.listeningApp.emit('progress-update', { percent, msg });
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why we need check this.listeningApp? Is can be undefined?

Copy link
Member Author

@hiroppy hiroppy Apr 3, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need this condition because this.setupProgressPlugin is called before this.createServer.

。◕ˇ_ˇ◕。 ~/p/w/webpack-dev-server (feature/emit-progress-update| 🎃 1 📦 1)  ᐅ npm run test:only -- progress-option

> webpack-dev-server@3.10.3 test:only /Users/hiroppy/programming/webpack/webpack-dev-server
> jest --forceExit "progress-option"

Test Suites: 1 failed, 1 total
Tests:       1 failed, 1 total
Snapshots:   0 total
Time:        3.755s
Ran all test suites matching /progress-option/i.
Force exiting Jest: Have you considered using `--detectOpenHandles` to detect async operations that kept running after all tests finished?
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! webpack-dev-server@3.10.3 test:only: `jest --forceExit "progress-option"`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the webpack-dev-server@3.10.3 test:only 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!     /Users/hiroppy/.npm/_logs/2020-04-03T10_59_27_800Z-debug.log
> npm run test:only -- progress-option

> webpack-dev-server@3.10.3 test:only /Users/hiroppy/programming/webpack/webpack-dev-server
> jest --forceExit "progress-option"

  console.info node_modules/webpack-log/src/loglevel/PrefixFactory.
js:55
    ℹ 「wds」: Project is running at http://localhost:8134/

  console.info node_modules/webpack-log/src/loglevel/PrefixFactory.js:55
    ℹ 「wds」: webpack output is served from undefined

  console.info node_modules/webpack-log/src/loglevel/PrefixFactory.js:55
    ℹ 「wds」: Content not from webpack is served from /Users/hiroppy/programming/webpack/webpack-dev-server

 PASS  test/server/progress-option.test.js
  progress
    output
      ✓ should show percentage progress without profile data (570ms
)

Test Suites: 1 passed, 1 total
Tests:       1 passed, 1 total
Snapshots:   0 total
Time:        2.107s
Ran all test suites matching /progress-option/i.
Force exiting Jest: Have you considered using `--detectOpenHandles` to detect async operations that kept running after all tests finished?

This log shows 2 situations that are added if or not.

}).apply(this.compiler);
}

Expand Down
10 changes: 6 additions & 4 deletions lib/servers/WebsocketServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,13 @@ module.exports = class WebsocketServer extends BaseServer {
const noop = () => {};

setInterval(() => {
this.wsServer.clients.forEach((ws) => {
if (ws.isAlive === false) return ws.terminate();
this.wsServer.clients.forEach((socket) => {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed by eslint

if (socket.isAlive === false) {
return socket.terminate();
}

ws.isAlive = false;
ws.ping(noop);
socket.isAlive = false;
socket.ping(noop);
});
}, this.server.heartbeatInterval);
}
Expand Down
8 changes: 7 additions & 1 deletion test/server/progress-option.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,13 @@ describe('progress', () => {
});

compiler.run(() => {});
server.listen(port, 'localhost');
const app = server.listen(port, 'localhost');

app.on('progress-update', ({ percent, msg }) => {
expect(percent).toBeGreaterThanOrEqual(0);
expect(percent).toBeLessThanOrEqual(100);
expect(typeof msg).toEqual('string');
});
});
});
});