-
Notifications
You must be signed in to change notification settings - Fork 58
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
Envinfo config file #176
base: main
Are you sure you want to change the base?
Envinfo config file #176
Changes from all commits
32eef8f
72033db
716ec72
40c1b39
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
const envinfo = require('../src/envinfo'); | ||
const path = require('path'); | ||
|
||
describe('envinfo.js config file', () => { | ||
test('will read the file and use it', async () => { | ||
const cwd = process.cwd(); | ||
process.chdir(path.join(__dirname, 'packages', path.sep, 'test-config')); | ||
try { | ||
const data = JSON.parse(await envinfo.run()); | ||
expect(Object.keys(data)).toEqual(['System', 'npmPackages']); | ||
expect(Object.keys(data.System)).toEqual(['OS', 'CPU']); | ||
} finally { | ||
process.chdir(cwd); | ||
} | ||
}); | ||
|
||
test('run will read the file and use it as a promise', async () => { | ||
const cwd = process.cwd(); | ||
process.chdir(path.join(__dirname, 'packages', path.sep, 'test-config-as-promise')); | ||
try { | ||
const data = JSON.parse(await envinfo.run()); | ||
expect(Object.keys(data)).toEqual(['System', 'Binaries']); | ||
expect(Object.keys(data.System)).toEqual(['OS', 'CPU']); | ||
expect(Object.keys(data.Binaries)).toEqual(['Node', 'npm']); | ||
} finally { | ||
process.chdir(cwd); | ||
} | ||
}); | ||
|
||
test('command line flags will override config file', async () => { | ||
const cwd = process.cwd(); | ||
process.chdir(path.join(__dirname, 'packages', path.sep, 'test-config')); | ||
|
||
const consoleLogSpy = jest.spyOn(global.console, 'log'); | ||
|
||
consoleLogSpy.mockImplementation(() => () => {}); | ||
|
||
try { | ||
await envinfo.cli({ | ||
markdown: true, | ||
json: false, | ||
npmPackages: false, | ||
system: true, | ||
console: true, | ||
}); | ||
expect(consoleLogSpy.mock.calls[0][0].includes('##')).toBe(true); | ||
} finally { | ||
consoleLogSpy.mockClear(); | ||
process.chdir(cwd); | ||
} | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module.exports = () => { | ||
return new Promise(resolve => | ||
resolve({ System: ['OS', 'CPU'], Binaries: ['Node', 'npm'], options: { json: true } }) | ||
); | ||
}; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"name": "test-config-as-promise", | ||
"version": "1.0.0", | ||
"dependencies": { | ||
"a": "1.0.0", | ||
"b": "1.0.0" | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = () => { | ||
return { System: ['OS', 'CPU'], npmPackages: true, options: { json: true } }; | ||
}; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"name": "test-config", | ||
"version": "1.0.0", | ||
"dependencies": { | ||
"a": "1.0.0", | ||
"b": "1.0.0" | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// needed for the dynamic requiring of a config file | ||
// https://stackoverflow.com/questions/42797313/webpack-dynamic-module-loader-by-require/54559637#54559637 | ||
module.exports = require; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
interesting, lol