lamed_io
Version:
82 lines (69 loc) • 3.41 kB
JavaScript
// Add module to test.runner.js
// 'use strict' // Comment out in test functions
console.log(`Starting ${__filename}...`) // comment line to remove simple logging
// ------------------------------------------------------
// localStorage_functions.test.js
// Purpose: The purpose of this to test localStorage_functions
// Date Created: 2020/01/28
// Created by : Perez Lamed van Niekerk
// ------------------------------------------------------
/* jshint esversion: 6 */
const _lio = require('../src/lamed_io')
const _localstorage = require('node-localstorage') // npm i node-localstorage -s
const _appSettings = new _localstorage.LocalStorage('./.appSettings')
const _app = require('../src/localstorage_functions')
const { con, unZip, unThrow, isTestRunner } = require('lamed_test') // eslint-disable-line
// ---------------------------------------------------
// Setup unit test
const show = !isTestRunner()
if (show) {
con.traceSet(0) // Activate trace when not run from test runner
con.useChalk(require('chalk')) // Give us some colour
}
con.logLine()
con.log(` --> ${__filename}`) // Show test case
con.logLine()
con.log(module.filename)
con.logBold(`--------------------------> ${arguments.callee.name}()`) // eslint-disable-line
let error = `In ${module.filename} --> ${arguments.callee.name}()` // eslint-disable-line
var _setupEnv = _app.storageGet(_appSettings, 'environment', 'JSN')
var _setupEnvName = _app.storageGet(_appSettings, 'environmentName', '(Unknown)')
var _setupEnvGlobal = _app.storageGet(_appSettings, 'environmentGlobal', true)
con.log({ _setupEnv, _setupEnvName, _setupEnvGlobal })
con.logLine()
const itemsHistory = _app.storageGetHistory(_appSettings)
con.log({ itemsHistory })
con.logLine()
const path = _lio.rootFolder() + 'templates/'
// This operation is very slow
// _app.storagePushHistory(_appSettings, path + 'asdfsadfasfassv1')
// _app.storagePushHistory(_appSettings, path + 'asdfsadfasfassv2')
// _app.storagePushHistory(_appSettings, path + 'asdfsadfasfassv3')
// _app.storagePushHistory(_appSettings, path + 'asdfsadfasfassv4')
// _app.storagePushHistory(_appSettings, path + 'asdfsadfasfassv5')
// _app.storagePushHistory(_appSettings, path + 'asdfsadfasfassv6')
// _app.storagePushHistory(_appSettings, path + 'asdfsadfasfassv7')
// _app.storagePushHistory(_appSettings, path + 'asdfsadfasfassv8')
// _app.storagePushHistory(_appSettings, path + 'asdfsadfasfassv7')
// _app.storagePushHistory(_appSettings, path + 'asdfsadfasfassv10')
_app.storagePushHistory(_appSettings, path + 'asdfsadfasfassv12')
_app.storagePushHistory(_appSettings, path + 'asdfsadfasfassv7')
_app.storagePushHistory(_appSettings, 'New item')
_app.storagePushHistory(_appSettings, 'New item2')
// time delay
con.logRed('Get History:')
const items = _app.storageGetHistory(_appSettings)
if (items[0] !== 'New item2') throw new Error(error)
if (items[1] !== 'New item') throw new Error(error)
const item1a = _app.storageGetHistoryItem(_appSettings, 1)
const item1b = _app.storageGetHistoryItem(_appSettings, '1')
con.log({ item1a, item1b })
if (items[0] !== item1a) throw new Error(error)
if (items[0] !== item1b) throw new Error(error)
// itemsHistory = _app.storageGetHistory(_appSettings)
// con.log({ itemsHistory })
con.logLine()
// con.log(__filename)
// ------------------------------------------------
con.logGreen(` √ ${__filename}`) // Success!!!
con.logLine()