Skip to content

Commit

Permalink
reader: use path.sep instead of [\\/] to be more obvious
Browse files Browse the repository at this point in the history
- for windows compat
  • Loading branch information
msimerson committed Apr 26, 2024
1 parent f9e0d39 commit ed34823
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 22 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/).

### Unreleased

### [1.2.3] - 2024-04-26

- reader: use path.sep instead of [\\/] to be more obvious

### [1.2.2] - 2024-04-24

- feat: getDir can parse different types of files in a dir
Expand Down Expand Up @@ -126,3 +130,6 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/).

[1.1.0]: https://github.com/haraka/haraka-config/releases/tag/1.1.0
[1.2.2]: https://github.com/haraka/haraka-config/releases/tag/v1.2.2
[1.2.3]: https://github.com/haraka/haraka-config/releases/tag/v1.2.3
[1.2.0]: https://github.com/haraka/haraka-config/releases/tag/v1.2.0
[1.2.1]: https://github.com/haraka/haraka-config/releases/tag/v1.2.1
2 changes: 1 addition & 1 deletion lib/reader.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class Reader {
}

// when loaded with require('haraka-config')
if (/node_modules\/haraka-config\/lib$/.test(__dirname)) {
if (__dirname.split(path.sep).slice(-3).toString() === 'node_modules,haraka-config,lib') {
config_dir_candidates = [
path.join(__dirname, '..', '..', '..', 'config'), // haraka/Haraka/*
path.join(__dirname, '..', '..', '..'), // npm packaged modules
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"name": "haraka-config",
"license": "MIT",
"description": "Haraka's config file loader",
"version": "1.2.2",
"version": "1.2.3",
"homepage": "http://haraka.github.io",
"repository": {
"type": "git",
Expand Down
32 changes: 12 additions & 20 deletions test/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,11 +234,10 @@ describe('get', function () {
_test_get('test', null, null, null, null)
})

it('test (non-existing, cached)', function (done) {
it('test (non-existing, cached)', function () {
process.env.WITHOUT_CONFIG_CACHE = ''
const cfg = this.config.get('test', null, null)
assert.deepEqual(cfg, null)
done()
})

it('test.ini, no opts', function () {
Expand Down Expand Up @@ -309,13 +308,14 @@ describe('get', function () {
_test_get('test.txt', null, null, null, null)
})

it('test.int', function () {
_test_get('test.int', null, null, null, 6)
})

it('test.flat, type=', function () {
_test_get('test.flat', null, null, null, 'line1')
})

// NOTE: the test.flat file had to be duplicated for these tests, to avoid
// the config cache from returning invalid results.

it('test.flat, type=value', function () {
_test_get('test.value', 'value', null, null, 'line1')
})
Expand Down Expand Up @@ -452,20 +452,15 @@ describe('getInt', function () {

const tmpFile = path.resolve('test', 'config', 'dir', '4.ext')

function cleanup(done) {
fs.unlink(tmpFile, () => {
done()
})
}

describe('getDir', function () {

beforeEach(function (done) {
process.env.NODE_ENV = 'test'
process.env.HARAKA = ''
process.env.WITHOUT_CONFIG_CACHE = '1'
clearRequireCache()
this.config = require('../config')
cleanup(done)
fs.unlink(tmpFile, () => done())
})

it('loads all files in dir', function (done) {
Expand All @@ -489,18 +484,15 @@ describe('getDir', function () {

it('reloads when file in dir is touched', function (done) {
this.timeout(3500)
if (/darwin/.test(process.platform)) {
// due to differences in fs.watch, this test is not reliable on Mac OS X
done()
return
}

const self = this
// due to differences in fs.watch, this test is not reliable on Mac OS X
if (/darwin/.test(process.platform)) return done()

let callCount = 0

function getDir() {
const getDir = () => {
const opts2 = { type: 'binary', watchCb: getDir }
self.config.getDir('dir', opts2, (err, files) => {
this.config.getDir('dir', opts2, (err, files) => {
// console.log('Loading: test/config/dir');
if (err) console.error(err)
callCount++
Expand Down

0 comments on commit ed34823

Please sign in to comment.