Skip to content

Commit

Permalink
Merge pull request #4 from Bellisario/add-tests
Browse files Browse the repository at this point in the history
Implement tests and minor changes
  • Loading branch information
Bellisario authored Oct 18, 2022
2 parents 39645b3 + c73b764 commit fe7db92
Show file tree
Hide file tree
Showing 14 changed files with 3,644 additions and 72 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ jobs:
- name: Install dependencies
run: npm install

- name: Test library
run: npm test

- name: Publish
run: npm run npm-publish
env:
Expand Down
26 changes: 26 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Test

on:
push:
branches: ["master"]
pull_request:
branches: ["master"]

jobs:
build:
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [14.x, 16.x, 18.x]

steps:
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: "npm"
- run: npm ci
- run: npm run build --if-present
- run: npm test
12 changes: 10 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Changelog
## v1.0.1 (30 June 2022)

## v1.2.0 (18 October 2022)

- Implement tests, NPM lockfile version 2, example files moved to `examples` folder and code formatting.

## v1.1.0 (30 June 2022)

- Now also patched devices will have the real hostname, instead of the default "localhost".

## v1.0.0 (2 June 2022)
- Initial release

- Initial release
19 changes: 16 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,26 @@
> Patches `os.hostname()` for Windows 7 devices using a not officially Node.js supported version
## Installation

```bash
npm install hostname-patcher
```

## Use cases

For some strange reason, `os.hostname()` is always broken if you're using a version of Node.js not officially supported in Windows 7 (v14.x.x and above), so, this module aims to keep it working.

> __News:__ Now also patched devices will have the real hostname, instead of the default "localhost".
## Don't want to use it? (Worried about adding this?)
You'll not have any problem using this patch, because it checks if it's needed before doing its work (see [here](https://github.com/Bellisario/hostname-patcher/blob/a5b63802a7d26481cd46846b1c10f327ceb2034f/lib/index.js#L6)).

You'll not have any problem using this patch, because it checks if it's needed before doing its work (see [here](https://github.com/Bellisario/hostname-patcher/blob/39645b3ba7a99aca39f60f59e7f51e2124522994/lib/index.js#L6)).

## How to use

### Common.js
To use with Common.js, just require it without even any variable assignment:

```js
// require patch first
require('hostname-patcher');
Expand All @@ -38,8 +44,11 @@ const { moduleUsingOS } = require('example');
// will output your real hostname if patch and if not
console.log(os.hostname());
```

### ES6

To use as an ES6 module, just import it:

```js
// import patch first
import 'hostname-patcher';
Expand All @@ -51,12 +60,16 @@ import { moduleUsingOS } from 'example';
// will output your real hostname if patch and if not
console.log(os.hostname());
```
> All examples available in the [test folder](https://github.com/Bellisario/hostname-patcher/tree/master/test).

> All examples available in the [examples folder](https://github.com/Bellisario/hostname-patcher/tree/master/examples).
## Tested modules
- [Nodemailer](https://github.com/nodemailer/nodemailer) (Common.js example [here](https://github.com/Bellisario/hostname-patcher/blob/master/test/Common.js/nodemailer.js) and ES6 [here](https://github.com/Bellisario/hostname-patcher/blob/master/test/ES6/nodemailer.mjs))

- [Nodemailer](https://github.com/nodemailer/nodemailer) (Common.js example [here](https://github.com/Bellisario/hostname-patcher/blob/master/examples/Common.js/nodemailer.js) and ES6 [here](https://github.com/Bellisario/hostname-patcher/blob/master/examples/ES6/nodemailer.mjs))

- __Let us know this patch is useful for other modules__

## For modules builders

Even if single projects can use this patch individually, would be great if modules themselves start using it, because it's a lot better for users experience and more practical.\
I know that this error occurs because these new Node.js versions are not anymore officially supported by Windows 7, but still today is a very usable and light OS for a lot people, so, please, keep supporting it, even if the Node.js community (but not everybody) want anymore.
2 changes: 1 addition & 1 deletion test/Common.js/index.js → examples/Common.js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ require('../../lib/index');
const os = require('os');

// will output your real hostname if patch and if not
console.log(os.hostname());
console.log(os.hostname());
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ async function sendTestMail() {
console.log('Preview URL: %s', nodemailer.getTestMessageUrl(info));
}

sendTestMail();
sendTestMail();
2 changes: 1 addition & 1 deletion test/ES6/index.mjs → examples/ES6/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ import '../../lib/index';
import os from 'os';

// will output your real hostname if patch and if not
console.log(os.hostname());
console.log(os.hostname());
2 changes: 1 addition & 1 deletion test/ES6/nodemailer.mjs → examples/ES6/nodemailer.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ async function sendTestMail() {
console.log('Preview URL: %s', nodemailer.getTestMessageUrl(info));
}

sendTestMail();
sendTestMail();
2 changes: 1 addition & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ if (needsPatch()) {
* https://github.com/nodemailer/nodemailer/issues/1410#issuecomment-1144628473
*/
os.hostname = () => patchHostname;
}
}
2 changes: 1 addition & 1 deletion lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const getHostname = () => {
let result;
try {
result = execSync('hostname').toString().trim();
} catch(e) {
} catch (e) {
result = 'localhost';
}
return result;
Expand Down
Loading

0 comments on commit fe7db92

Please sign in to comment.