|
@@ -58,11 +58,6 @@ const CLEAR = { ctrl: true, name: 'u' }; |
|
|
const historyFixturePath = fixtures.path('.node_repl_history'); |
|
|
const historyPath = path.join(tmpdir.path, '.fixture_copy_repl_history'); |
|
|
const historyPathFail = fixtures.path('nonexistent_folder', 'filename'); |
|
|
const oldHistoryPathObj = fixtures.path('old-repl-history-file-obj.json'); |
|
|
const oldHistoryPathFaulty = fixtures.path('old-repl-history-file-faulty.json'); |
|
|
const oldHistoryPath = fixtures.path('old-repl-history-file.json'); |
|
|
const enoentHistoryPath = fixtures.path('enoent-repl-history-file.json'); |
|
|
const emptyHistoryPath = fixtures.path('.empty-repl-history-file'); |
|
|
const defaultHistoryPath = path.join(tmpdir.path, '.node_repl_history'); |
|
|
const emptyHiddenHistoryPath = fixtures.path('.empty-hidden-repl-history-file'); |
|
|
const devNullHistoryPath = path.join(tmpdir.path, |
|
@@ -72,23 +67,10 @@ const prompt = '> '; |
|
|
const replDisabled = '\nPersistent history support disabled. Set the ' + |
|
|
'NODE_REPL_HISTORY environment\nvariable to a valid, ' + |
|
|
'user-writable path to enable.\n'; |
|
|
const convertMsg = '\nConverted old JSON repl history to line-separated ' + |
|
|
'history.\nThe new repl history file can be found at ' + |
|
|
`${defaultHistoryPath}.\n`; |
|
|
const homedirErr = '\nError: Could not get the home directory.\n' + |
|
|
'REPL session history will not be persisted.\n'; |
|
|
const replFailedRead = '\nError: Could not open history file.\n' + |
|
|
'REPL session history will not be persisted.\n'; |
|
|
const oldHistoryFailedOpen = '\nError: Could not open old history file.\n' + |
|
|
'REPL session history will not be persisted.\n'; |
|
|
const oldHistoryFailedParse = '\nError: Could not parse old history file.\n' + |
|
|
'REPL session history will not be persisted.\n'; |
|
|
const oldHistoryObj = '\nError: The old history file data has to be an Array' + |
|
|
'.\nREPL session history will not be persisted.\n'; |
|
|
const sameHistoryFilePaths = '\nThe old repl history file has the same name ' + |
|
|
'and location as the new one i.e., ' + |
|
|
`${defaultHistoryPath}` + |
|
|
' and is empty.\nUsing it as is.\n'; |
|
|
|
|
|
const tests = [ |
|
|
{ |
|
@@ -101,84 +83,28 @@ const tests = [ |
|
|
test: [UP], |
|
|
expected: [prompt, replDisabled, prompt] |
|
|
}, |
|
|
{ |
|
|
env: { NODE_REPL_HISTORY_FILE: enoentHistoryPath }, |
|
|
test: [UP], |
|
|
expected: [prompt, oldHistoryFailedOpen, prompt] |
|
|
}, |
|
|
{ |
|
|
env: { NODE_REPL_HISTORY_FILE: oldHistoryPathObj }, |
|
|
test: [UP], |
|
|
expected: [prompt, oldHistoryObj, prompt] |
|
|
}, |
|
|
{ |
|
|
env: { NODE_REPL_HISTORY_FILE: oldHistoryPathFaulty }, |
|
|
test: [UP], |
|
|
expected: [prompt, oldHistoryFailedParse, prompt] |
|
|
}, |
|
|
{ |
|
|
env: { NODE_REPL_HISTORY: '', |
|
|
NODE_REPL_HISTORY_FILE: oldHistoryPath }, |
|
|
test: [UP], |
|
|
expected: [prompt, replDisabled, prompt] |
|
|
}, |
|
|
{ |
|
|
env: { NODE_REPL_HISTORY_FILE: emptyHistoryPath }, |
|
|
test: [UP], |
|
|
expected: [prompt, convertMsg, prompt] |
|
|
}, |
|
|
{ |
|
|
env: { NODE_REPL_HISTORY_FILE: defaultHistoryPath }, |
|
|
test: [UP], |
|
|
expected: [prompt, sameHistoryFilePaths, prompt] |
|
|
}, |
|
|
{ |
|
|
env: { NODE_REPL_HISTORY: historyPath }, |
|
|
test: [UP, CLEAR], |
|
|
expected: [prompt, `${prompt}'you look fabulous today'`, prompt] |
|
|
}, |
|
|
{ |
|
|
env: { NODE_REPL_HISTORY: historyPath, |
|
|
NODE_REPL_HISTORY_FILE: oldHistoryPath }, |
|
|
test: [UP, CLEAR], |
|
|
expected: [prompt, `${prompt}'you look fabulous today'`, prompt] |
|
|
}, |
|
|
{ |
|
|
env: { NODE_REPL_HISTORY: historyPath, |
|
|
NODE_REPL_HISTORY_FILE: '' }, |
|
|
test: [UP, CLEAR], |
|
|
expected: [prompt, `${prompt}'you look fabulous today'`, prompt] |
|
|
}, |
|
|
{ |
|
|
env: {}, |
|
|
test: [UP], |
|
|
expected: [prompt] |
|
|
}, |
|
|
{ |
|
|
env: { NODE_REPL_HISTORY_FILE: oldHistoryPath }, |
|
|
test: [UP, CLEAR, '\'42\'', ENTER], |
|
|
expected: [prompt, convertMsg, prompt, `${prompt}'=^.^='`, prompt, '\'', |
|
|
'4', '2', '\'', '\'42\'\n', prompt, prompt], |
|
|
test: [UP, '\'42\'', ENTER], |
|
|
expected: [prompt, '\'', '4', '2', '\'', '\'42\'\n', prompt, prompt], |
|
|
clean: false |
|
|
}, |
|
|
{ // Requires the above testcase |
|
|
{ // Requires the above test case |
|
|
env: {}, |
|
|
test: [UP, UP, ENTER], |
|
|
expected: [prompt, `${prompt}'42'`, `${prompt}'=^.^='`, '\'=^.^=\'\n', |
|
|
prompt] |
|
|
expected: [prompt, `${prompt}'42'`, '\'42\'\n', prompt] |
|
|
}, |
|
|
{ |
|
|
env: { NODE_REPL_HISTORY: historyPath, |
|
|
NODE_REPL_HISTORY_SIZE: 1 }, |
|
|
test: [UP, UP, CLEAR], |
|
|
expected: [prompt, `${prompt}'you look fabulous today'`, prompt] |
|
|
}, |
|
|
{ |
|
|
env: { NODE_REPL_HISTORY_FILE: oldHistoryPath, |
|
|
NODE_REPL_HISTORY_SIZE: 1 }, |
|
|
test: [UP, UP, UP, CLEAR], |
|
|
expected: [prompt, convertMsg, prompt, `${prompt}'=^.^='`, prompt] |
|
|
}, |
|
|
{ |
|
|
env: { NODE_REPL_HISTORY: historyPathFail, |
|
|
NODE_REPL_HISTORY_SIZE: 1 }, |
|
|