@@ -1363,7 +1363,7 @@ describe('e2e', function () {
1363
1363
let logBasePath : string ;
1364
1364
let historyPath : string ;
1365
1365
let readConfig : ( ) => Promise < any > ;
1366
- let readLogfile : ( ) => Promise < LogEntry [ ] > ;
1366
+ let readLogFile : ( ) => Promise < LogEntry [ ] > ;
1367
1367
let startTestShell : ( ...extraArgs : string [ ] ) => Promise < TestShell > ;
1368
1368
1369
1369
beforeEach ( function ( ) {
@@ -1400,7 +1400,7 @@ describe('e2e', function () {
1400
1400
}
1401
1401
readConfig = async ( ) =>
1402
1402
EJSON . parse ( await fs . readFile ( configPath , 'utf8' ) ) ;
1403
- readLogfile = async ( ) => {
1403
+ readLogFile = async ( ) => {
1404
1404
if ( ! shell . logId ) {
1405
1405
throw new Error ( 'Shell does not have a logId associated with it' ) ;
1406
1406
}
@@ -1515,7 +1515,7 @@ describe('e2e', function () {
1515
1515
} ) ;
1516
1516
1517
1517
describe ( 'log file' , function ( ) {
1518
- it ( 'does not create a log if global config has disableLogging' , async function ( ) {
1518
+ it ( 'does not get created if global config has disableLogging' , async function ( ) {
1519
1519
const globalConfig = path . join ( homedir , 'globalconfig.conf' ) ;
1520
1520
await fs . writeFile ( globalConfig , 'mongosh:\n disableLogging: true' ) ;
1521
1521
shell = this . startTestShell ( {
@@ -1536,9 +1536,38 @@ describe('e2e', function () {
1536
1536
expect ( shell . logId ) . equals ( null ) ;
1537
1537
} ) ;
1538
1538
1539
+ it ( 'gets created if global config has disableLogging set to false' , async function ( ) {
1540
+ const globalConfig = path . join ( homedir , 'globalconfig.conf' ) ;
1541
+ await fs . writeFile ( globalConfig , 'mongosh:\n disableLogging: false' ) ;
1542
+ shell = this . startTestShell ( {
1543
+ args : [ '--nodb' ] ,
1544
+ env : {
1545
+ ...env ,
1546
+ MONGOSH_GLOBAL_CONFIG_FILE_FOR_TESTING : globalConfig ,
1547
+ } ,
1548
+ forceTerminal : true ,
1549
+ } ) ;
1550
+ await shell . waitForPrompt ( ) ;
1551
+ expect (
1552
+ await shell . executeLine ( 'config.get("disableLogging")' )
1553
+ ) . to . include ( 'false' ) ;
1554
+ shell . assertNoErrors ( ) ;
1555
+
1556
+ expect ( await shell . executeLine ( 'print(123 + 456)' ) ) . to . include ( '579' ) ;
1557
+ expect ( shell . logId ) . not . equal ( null ) ;
1558
+
1559
+ const log = await readLogFile ( ) ;
1560
+ expect (
1561
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
1562
+ log . filter (
1563
+ ( logEntry ) => logEntry . attr ?. input === 'print(123 + 456)'
1564
+ )
1565
+ ) . to . have . lengthOf ( 1 ) ;
1566
+ } ) ;
1567
+
1539
1568
it ( 'creates a log file that keeps track of session events' , async function ( ) {
1540
1569
expect ( await shell . executeLine ( 'print(123 + 456)' ) ) . to . include ( '579' ) ;
1541
- const log = await readLogfile ( ) ;
1570
+ const log = await readLogFile ( ) ;
1542
1571
expect (
1543
1572
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
1544
1573
log . filter (
@@ -1547,9 +1576,9 @@ describe('e2e', function () {
1547
1576
) . to . have . lengthOf ( 1 ) ;
1548
1577
} ) ;
1549
1578
1550
- it ( 'does not write to the log file after disableLogging is set to true' , async function ( ) {
1579
+ it ( 'does not write to the log after disableLogging is set to true' , async function ( ) {
1551
1580
expect ( await shell . executeLine ( 'print(123 + 456)' ) ) . to . include ( '579' ) ;
1552
- const log = await readLogfile ( ) ;
1581
+ const log = await readLogFile ( ) ;
1553
1582
expect (
1554
1583
log . filter (
1555
1584
( logEntry ) => logEntry . attr ?. input === 'print(123 + 456)'
@@ -1559,7 +1588,7 @@ describe('e2e', function () {
1559
1588
await shell . executeLine ( `config.set("disableLogging", true)` ) ;
1560
1589
expect ( await shell . executeLine ( 'print(579 - 123)' ) ) . to . include ( '456' ) ;
1561
1590
1562
- const logAfterDisabling = await readLogfile ( ) ;
1591
+ const logAfterDisabling = await readLogFile ( ) ;
1563
1592
expect (
1564
1593
logAfterDisabling . filter (
1565
1594
( logEntry ) => logEntry . attr ?. input === 'print(579 - 123)'
@@ -1572,6 +1601,43 @@ describe('e2e', function () {
1572
1601
) . to . have . lengthOf ( 1 ) ;
1573
1602
} ) ;
1574
1603
1604
+ it ( 'starts writing to a new log from the point where disableLogging is set to false' , async function ( ) {
1605
+ await shell . executeLine ( `config.set("disableLogging", true)` ) ;
1606
+ expect ( await shell . executeLine ( 'print(123 + 456)' ) ) . to . include ( '579' ) ;
1607
+ const log = await readLogFile ( ) ;
1608
+ const oldLogId = shell . logId ;
1609
+ expect ( oldLogId ) . not . null ;
1610
+
1611
+ expect (
1612
+ log . filter (
1613
+ ( logEntry ) => logEntry . attr ?. input === 'print(123 + 456)'
1614
+ )
1615
+ ) . to . have . lengthOf ( 0 ) ;
1616
+
1617
+ await shell . executeLine ( `config.set("disableLogging", false)` ) ;
1618
+
1619
+ expect (
1620
+ await shell . executeLine ( 'config.get("disableLogging")' )
1621
+ ) . to . include ( 'false' ) ;
1622
+
1623
+ expect ( await shell . executeLine ( 'print(579 - 123)' ) ) . to . include ( '456' ) ;
1624
+
1625
+ const newLogId = shell . logId ;
1626
+ expect ( newLogId ) . not . null ;
1627
+ expect ( oldLogId ) . not . equal ( newLogId ) ;
1628
+ const logsAfterEnabling = await readLogFile ( ) ;
1629
+ expect (
1630
+ logsAfterEnabling . filter (
1631
+ ( logEntry ) => logEntry . attr ?. input === 'print(579 - 123)'
1632
+ )
1633
+ ) . to . have . lengthOf ( 1 ) ;
1634
+ expect (
1635
+ logsAfterEnabling . filter (
1636
+ ( logEntry ) => logEntry . attr ?. input === 'print(123 + 456)'
1637
+ )
1638
+ ) . to . have . lengthOf ( 0 ) ;
1639
+ } ) ;
1640
+
1575
1641
it ( 'includes information about the driver version' , async function ( ) {
1576
1642
const connectionString = await testServer . connectionString ( ) ;
1577
1643
expect (
@@ -1580,7 +1646,7 @@ describe('e2e', function () {
1580
1646
)
1581
1647
) . to . include ( 'test' ) ;
1582
1648
await eventually ( async ( ) => {
1583
- const log = await readLogfile ( ) ;
1649
+ const log = await readLogFile ( ) ;
1584
1650
expect (
1585
1651
log . filter (
1586
1652
( logEntry ) => typeof logEntry . attr ?. driver ?. version === 'string'
0 commit comments