JoyOfJavaScript / joj

Docker setup for code listings shown in Joy Of JavaScript
MIT License
80 stars 35 forks source link

Some tests fail #1

Closed Lazarus404 closed 5 years ago

Lazarus404 commented 5 years ago

I'm reviewing your chapters. On running npm install and npm run build in the blockchain and chapter-listings directories, I then run npm run test-all from the chapter-listings directory and receive test errors. I get more-or-less the same errors running in Docker Compose.

npm run test-all

> @joj/chapter-listings@0.1.0 test-all /home/jahred/Documents/writing/joj/src/chapter-listings
> rm -rf _babel && babel src --out-dir _babel/src --keep-file-extension; mjs-mocha _babel; rm -rf _babel

@babel/preset-env: `DEBUG` option

Using targets:
{
  "node": "12.7"
}

Using modules transform: false

Using plugins:
  syntax-async-generators { "node":"12.7" }
  syntax-object-rest-spread { "node":"12.7" }
  syntax-json-strings { "node":"12.7" }
  syntax-optional-catch-binding { "node":"12.7" }

Using polyfills: No polyfills were added, since the `useBuiltIns` option was not set.
Successfully compiled 55 files with Babel.
  1.3.2 - JavaScript objects: no fluff, just stuff:
    ✔ Object literals passed
    ✔ Object constructor passed
    ✔ Classes passed
    ✔ Delegation passed
    ✔ Functional Mixins passed

 ✔ All 5 tests passed

  1.3.4 - Inheritance vs composition: why not both?:
    ✔ Block class with composed mixins passed
    ✔ Object.assign vs compose passed

 ✔ All 2 tests passed

  1.4.1 - Algebraic Coding:
    ✔ Implement read using Validation ADT passed
    ✔ countBlocksInFile using Validation#map passed

 ✔ All 2 tests passed

  1.4 - Higher-order functional programming:
    ✔ Functions are objects passed
    ✔ Compose using reduce passed

 ✔ All 2 tests passed

  1.5 - Separating concerns like a pro:
Execution time: 0s 0.011015ms
    ✔ Perf counter using proxy passed

 ✔ All 1 tests passed

  1.6 - Taming asynchronous code:
Result is:  7
    ✔ CountBlocksInFile using async/await passed

 ✔ All 1 tests passed

  1.7 - Types for JavaScript?:

 ✔ All 0 tests passed

  2.1.2 - Differential inheritance:
    ✔ Adds calculateHash to transaction passed
    ✔ Differentiate using Object.setPrototypeOf passed

 ✔ All 2 tests passed

  2.1 - Reviewing "prototypal inheritance":
    ✔ Simple proto passed
    ✔ Transaction objects linked using a basic prototype setup passed

 ✔ All 2 tests passed

  2.2 - Constructor functions:
    ✔ Transaction hierarchy using constructor functions passed
    ✔ Omit new.target check passed
    ✔ Fat-finger prototype references passed

 ✔ All 3 tests passed

  2.3.2 - Limitations of JavaScript class system:
Transaction from luke@joj.com to luis@joj.com
    ✔ Studies Fragile base object passed

 ✔ All 1 tests passed

  2.3.1 - Prototypes !== classes:
    ✔ Listing 2.3 Transaction hierarchy using constructor functions passed
    ✔ Transaction using IIFE passed

 ✔ All 2 tests passed

  3.1 - Object/behavior delegation with OLOO:
    ✔ Listing 3.1 HashTransaction using simple object linking passed

 ✔ All 1 tests passed

  3.2.1 - Explicit Delegation:
    ✔ Listing 3.2 Explicit delegation from Blockchain to its internal array store passed
    ✔ Shows a version of Blockchain based on an internal Map passed

 ✔ All 2 tests passed

  3.2.2 - Implicit Delegation:
    ✔ Using a constructor function passed
    ✔ Classes passed
    ✔ Array-like + constructor function passed
    ✔ OLOO passed
    ✔ Listing 3.2 - Modeling Transaction using behavior delegation (OLOO) passed

 ✔ All 5 tests passed

  3.3 - Functional Mixins:
    ✔ 3.3.1 - Object.assign uncovered passed

 ✔ All 1 tests passed

  3.3 - Functional Mixins:
    ✔ 3.3.2 - Assignment vs definition passed

 ✔ All 1 tests passed

  3.4.1 - Mixin linearization:
    ✔ Simple mixin linearization passed
    ✔ Blockchain definition using mixins passed
    ✔ Listing 3.8 Block definition passed
    ✔ Listing 3.9 Wallet object passed

 ✔ All 4 tests passed

Base is /home/jahred/Documents/writing/joj/src/chapter-listings/wallets
  3.4 - Assembling objects using mixins:
    ✔ Simple mixin composition passed
    ✔ Simple mixin composition using spread operator passed
    ✔ Listing 3.3 Transaction object using mixin concatenation passed
    ✔ Listing 3.4 HasHash mixin passed
    ✔ Listing 3.5 HasSignature mixin passed

 ✔ All 5 tests passed

  4.1 - What is functional programming, exactly?:
    ✔ Demonstrates using higher-order functions passed
    ✔ 4.1.2 - Shows why Array.sort is impure passed

  4.1.2 - Convert imperative to functional:
    ✔ Imperative passed
    ✔ Functional passed

 ✔ All 4 tests passed

  4.2.1 - Decomposing complex code:
    ✔ Before decomposing passed
    ✔ After decomposing passed
    ✔ After decomposing, using a recursive version of computeCipher passed

 ✔ All 3 tests passed

  4.2.2 - Working with side effects:
    ✗ Imperative function that counts words in a text file failed
Error: ENOENT: no such file or directory, open '/home/jahred/Documents/writing/joj/src/chapter-listings/src/ch04/sample.txt'
    at Object.openSync (fs.js:447:3)
    at Proxy.readFileSync (fs.js:349:35)
    at countWordsInFile (file:///home/jahred/Documents/writing/joj/src/chapter-listings/_babel/src/ch04/4-2-2.spec.mjs:20:29)
    at Object.callback (file:///home/jahred/Documents/writing/joj/src/chapter-listings/node_modules/mjs-mocha/temp/3fn16.mjs:157:18)
    at processLevel (file:///home/jahred/Documents/writing/joj/src/chapter-listings/node_modules/mjs-mocha/temp/3fn16.mjs:94:20)
    at processTicksAndRejections (internal/process/task_queues.js:85:5)
    at async processLevel (file:///home/jahred/Documents/writing/joj/src/chapter-listings/node_modules/mjs-mocha/temp/3fn16.mjs:110:7) {
  errno: -2,
  syscall: 'open',
  code: 'ENOENT',
  path: '/home/jahred/Documents/writing/joj/src/chapter-listings/src/ch04/sample.txt'
}
    ✗ Counting words using manual composition failed
Error: ENOENT: no such file or directory, open '/home/jahred/Documents/writing/joj/src/chapter-listings/src/ch04/sample.txt'
    at Object.openSync (fs.js:447:3)
    at readFileSync (fs.js:349:35)
    at countWordsInFile (file:///home/jahred/Documents/writing/joj/src/chapter-listings/node_modules/mjs-mocha/temp/3fn16.mjs:160:57)
    at Object.callback (file:///home/jahred/Documents/writing/joj/src/chapter-listings/node_modules/mjs-mocha/temp/3fn16.mjs:161:18)
    at processLevel (file:///home/jahred/Documents/writing/joj/src/chapter-listings/node_modules/mjs-mocha/temp/3fn16.mjs:94:20)
    at processTicksAndRejections (internal/process/task_queues.js:85:5)
    at async processLevel (file:///home/jahred/Documents/writing/joj/src/chapter-listings/node_modules/mjs-mocha/temp/3fn16.mjs:110:7) {
  errno: -2,
  syscall: 'open',
  code: 'ENOENT',
  path: '/home/jahred/Documents/writing/joj/src/chapter-listings/src/ch04/sample.txt'
}
    ✗ Counting words using compose2 failed
Error: ENOENT: no such file or directory, open '/home/jahred/Documents/writing/joj/src/chapter-listings/src/ch04/sample.txt'
    at Object.openSync (fs.js:447:3)
    at readFileSync (fs.js:349:35)
    at file:///home/jahred/Documents/writing/joj/src/blockchain/dist/lib/fp/combinators.mjs:5:50
    at file:///home/jahred/Documents/writing/joj/src/blockchain/dist/lib/fp/combinators.mjs:5:50
    at Object.callback (file:///home/jahred/Documents/writing/joj/src/chapter-listings/node_modules/mjs-mocha/temp/3fn16.mjs:165:18)
    at processLevel (file:///home/jahred/Documents/writing/joj/src/chapter-listings/node_modules/mjs-mocha/temp/3fn16.mjs:94:20)
    at processTicksAndRejections (internal/process/task_queues.js:85:5)
    at async processLevel (file:///home/jahred/Documents/writing/joj/src/chapter-listings/node_modules/mjs-mocha/temp/3fn16.mjs:110:7) {
  errno: -2,
  syscall: 'open',
  code: 'ENOENT',
  path: '/home/jahred/Documents/writing/joj/src/chapter-listings/src/ch04/sample.txt'
}
    ✔ Shows simple reduce passed
    ✗ countWordsInFile implemented with compose failed
Error: ENOENT: no such file or directory, open '/home/jahred/Documents/writing/joj/src/chapter-listings/src/ch04/sample.txt'
    at Object.openSync (fs.js:447:3)
    at readFileSync (fs.js:349:35)
    at file:///home/jahred/Documents/writing/joj/src/blockchain/dist/lib/fp/combinators.mjs:5:50
    at Object.callback (file:///home/jahred/Documents/writing/joj/src/chapter-listings/node_modules/mjs-mocha/temp/3fn16.mjs:179:18)
    at processLevel (file:///home/jahred/Documents/writing/joj/src/chapter-listings/node_modules/mjs-mocha/temp/3fn16.mjs:94:20)
    at processTicksAndRejections (internal/process/task_queues.js:85:5)
    at async processLevel (file:///home/jahred/Documents/writing/joj/src/chapter-listings/node_modules/mjs-mocha/temp/3fn16.mjs:110:7) {
  errno: -2,
  syscall: 'open',
  code: 'ENOENT',
  path: '/home/jahred/Documents/writing/joj/src/chapter-listings/src/ch04/sample.txt'
}

 ✗ 4/5 failed

  4.2 - Composition: the functional way:
    ✔ Demonstrates compose2 passed

 ✔ All 1 tests passed

  4.3.1 - Curried Function Application:
    ✔ Working with prop and props passed
    ✔ Curried versions of prop passed

 ✔ All 2 tests passed

  4.3.2 - The curry and composition duo:
    ✔ Secure compute cipher for HasHash mixin passed
    ✔ Implements HasHash mixin passed

 ✔ All 2 tests passed

  4.3 - Lazy coding:
    ✔ Use default value to assert preconditions passed
    ✔ Shows add manually curried passed

 ✔ All 2 tests passed

  4.4 - Working with immutable objects:
    ✔ Working with Money Value Object passed
    ✔ Implements HasHash mixin by sending copy of data passed

 ✔ All 2 tests passed

  4.5 - Point-free coding:
    ✗ Count words/blocks in file as point-free failed
Error: ENOENT: no such file or directory, open '/home/jahred/Documents/writing/joj/src/chapter-listings/src/ch04/sample.txt'
    at Object.openSync (fs.js:447:3)
    at readFileSync (fs.js:349:35)
    at file:///home/jahred/Documents/writing/joj/src/blockchain/dist/lib/fp/combinators.mjs:5:50
    at Object.callback (file:///home/jahred/Documents/writing/joj/src/chapter-listings/_babel/src/ch04/4-5.spec.mjs:28:18)
    at processLevel (file:///home/jahred/Documents/writing/joj/src/chapter-listings/node_modules/mjs-mocha/temp/xfngbc.mjs:94:20)
    at processTicksAndRejections (internal/process/task_queues.js:85:5)
    at async processLevel (file:///home/jahred/Documents/writing/joj/src/chapter-listings/node_modules/mjs-mocha/temp/xfngbc.mjs:110:7) {
  errno: -2,
  syscall: 'open',
  code: 'ENOENT',
  path: '/home/jahred/Documents/writing/joj/src/chapter-listings/src/ch04/sample.txt'
}

 ✗ 1/1 failed

  4.6 - Imperative to functional transformation:
    ✔ Calculate balance in Wallet using FP passed
    ✔ Calculate balance in Wallet using FP with flatMap passed
    ✔ Calculate balance in Wallet using FP in point-free style passed

 ✔ All 3 tests passed

  4.7 - Looking into the future:
    ✔ Function binding passed
    ✔ Pipelining passed

 ✔ All 2 tests passed

  4 - Introduction:
    ✔ Demonstrates that JavaScript functions are objects too by printing its parent constructor passed

 ✔ All 1 tests passed

  5.1.1 - Using containers for encapsulation and immutability:
    ✔ Mapping functions on an array passed
    ✔ Implementing a “contextless” container by extending from Array passed

 ✔ All 2 tests passed

  5.1.2 - Contextual composition:
    ✔ Uses compose in place of Id.map passed

 ✔ All 1 tests passed

  5.1.3 - JavaScript data types:
    ✔ Tests JS primitive types passed

 ✔ All 1 tests passed

  5.2 - New Array APIs: {flat, flatMap}:
    ✔ Intro passed
    ✔ 5.2.1 Array.prototype.flat passed
    ✔ 5.2.2 Array.prototype.flatMap passed

 ✔ All 3 tests passed

  5.3 - The map/compose correspondence:
    ✔ map passed
    ✔ flatMap passed

 ✔ All 2 tests passed

  5.4 - Universal protocols:
    ✔ 5.4.1 - Functors: identity and composition passed
    ✔ Functor mixin passed
    ✔ Monads: Left identity, Right identity, Associativity passed
    ✔ Monad mixin passed

 ✔ All 4 tests passed

  5.5 - Kinds of algebraic data types:
    ✔ Records passed

 ✔ All 1 tests passed

  5.6.4 - Higher-kinded composition with Validation:
Block {
  index: 2,
  previousHash: '737dd980481c43014739ff3033a1ad5cd116eca233eff8c5c766ec2f78268084',
  data: [ 'some data' ],
  nonce: 0,
  difficulty: 0,
  timestamp: 1564400019335,
  hash: '2b505ee8c0c48cc6fd3fa68274c47087b15d1af404a01e146f7a7b4613c3e44c'
}
    ✔ Shows isValid using flatMapo passed

 ✔ All 1 tests passed

  5.6.5 - 1.6.5 Point-free coding with ADTs:
Block {
  index: 2,
  previousHash: 'ad1dc90aaff2d2e7c8fb6d744012e11633ccc386193ab6352c71540b5d565b9c',
  data: [ 'some data' ],
  nonce: 0,
  difficulty: 0,
  timestamp: 1564400019395,
  hash: '6d16927972721725663f5dcbf40c223f4eca919c2f24b35e04b20169789b1f99'
}
    ✔ Shows isValid using composeM passed

 ✔ All 1 tests passed

  5.6.6 - Validating complex data structures:
Failure (Block out of order [previous (2) next (0)])
    ✔ Calls isValid recusively on the entire blockchain and its items passed

 ✔ All 1 tests passed

  5.6.7 - Third party integration:
    ✔ Using Ramda passed

 ✔ All 1 tests passed

  5.6 - Implementing the Validation ADT:
    ✔ 5.6.2 - Modeling success or failure passed
    ✗ Parent Validation class with Success and Failure subclasses failed
AssertionError: expected false to be true
    at Object.callback (file:///home/jahred/Documents/writing/joj/src/chapter-listings/_babel/src/ch05/5-6.spec.mjs:231:12)
    at processLevel (file:///home/jahred/Documents/writing/joj/src/chapter-listings/node_modules/mjs-mocha/temp/x64hq.mjs:94:20)
    at processTicksAndRejections (internal/process/task_queues.js:85:5)
    at async processLevel (file:///home/jahred/Documents/writing/joj/src/chapter-listings/node_modules/mjs-mocha/temp/x64hq.mjs:110:7) {
  message: 'expected false to be true',
  showDiff: true,
  actual: false,
  expected: true
}
Block {
  index: 2,
  previousHash: '996570b54b03a127984e489664626db2cce30cdea6243e05aa5606579fffcb1a',
  data: [ 'some data' ],
  nonce: 0,
  difficulty: 0,
  timestamp: 1564400019646,
  hash: '8057c30ba57a140371b8b01146a026448f82e370b57f8f660de835280182aa0f'
}
    ✔ Validating a block passed

 ✗ 1/3 failed

  5.7 - ADTs that help shape the future of JavaScript:
    ✔ 5.7.1 Optional chaining passed
    ✔ Maybe/Result passed
    ✔ 5.7.2 Try and throw expressions passed

 ✔ All 3 tests passed

  6 - Scratch Pad:
TBD
    ✔ CJS case passed
    ✔ ESM case passed

 ✔ All 2 tests passed

  Extending from Arrays:
    ✔ Should extend from Array using classes passed
    ✔ Should extend from Array using classes (set species) passed
    ✔ Should extend from Array using prototype passed
    ✔ Should use structure typing (array-like) to behave like an array passed

 ✔ All 4 tests passed

  Bind proposal:
    ✔ prop passed
    ✔ map passed
    ✔ Money passed
    ✔ Extracts from Array passed

 ✔ All 4 tests passed

  Calculate hash:
    ✔ calculates a hash using composition passed
    ✔ calculates a hash using composition and recursion passed

 ✔ All 2 tests passed

  Combining classes with mixins:
funds 0
funds 20
    ✔ Should create an amphibian object passed

 ✔ All 1 tests passed

  Count words:
Result is:  3
    ✔ compose2 passed
    ✔ pipeline passed
    ✗ Count blocks imperative failed
Error: ENOENT: no such file or directory, open '/home/jahred/Documents/writing/joj/src/chapter-listings/src/misc/sample.txt'
    at Object.openSync (fs.js:447:3)
    at Proxy.readFileSync (fs.js:349:35)
    at countWords (file:///home/jahred/Documents/writing/joj/src/chapter-listings/_babel/src/misc/countwords.spec.mjs:36:25)
    at Object.callback (file:///home/jahred/Documents/writing/joj/src/chapter-listings/node_modules/mjs-mocha/temp/7ajtyl.mjs:173:20)
    at processLevel (file:///home/jahred/Documents/writing/joj/src/chapter-listings/node_modules/mjs-mocha/temp/7ajtyl.mjs:94:20)
    at processTicksAndRejections (internal/process/task_queues.js:85:5)
    at async processLevel (file:///home/jahred/Documents/writing/joj/src/chapter-listings/node_modules/mjs-mocha/temp/7ajtyl.mjs:110:7) {
  errno: -2,
  syscall: 'open',
  code: 'ENOENT',
  path: '/home/jahred/Documents/writing/joj/src/chapter-listings/src/misc/sample.txt'
}
    ✗ Count blocks using composition failed
Error: ENOENT: no such file or directory, open '/home/jahred/Documents/writing/joj/src/chapter-listings/src/misc/sample.txt'
    at Object.openSync (fs.js:447:3)
    at readFileSync (fs.js:349:35)
    at file:///home/jahred/Documents/writing/joj/src/chapter-listings/node_modules/mjs-mocha/temp/7ajtyl.mjs:149:43
    at Object.callback (file:///home/jahred/Documents/writing/joj/src/chapter-listings/node_modules/mjs-mocha/temp/7ajtyl.mjs:187:20)
    at processLevel (file:///home/jahred/Documents/writing/joj/src/chapter-listings/node_modules/mjs-mocha/temp/7ajtyl.mjs:94:20)
    at processTicksAndRejections (internal/process/task_queues.js:85:5)
    at async processLevel (file:///home/jahred/Documents/writing/joj/src/chapter-listings/node_modules/mjs-mocha/temp/7ajtyl.mjs:110:7) {
  errno: -2,
  syscall: 'open',
  code: 'ENOENT',
  path: '/home/jahred/Documents/writing/joj/src/chapter-listings/src/misc/sample.txt'
}
    ✗ Count blocks using compose2 failed
Error: ENOENT: no such file or directory, open '/home/jahred/Documents/writing/joj/src/chapter-listings/src/misc/sample.txt'
    at Object.openSync (fs.js:447:3)
    at readFileSync (fs.js:349:35)
    at file:///home/jahred/Documents/writing/joj/src/chapter-listings/node_modules/mjs-mocha/temp/7ajtyl.mjs:149:43
    at file:///home/jahred/Documents/writing/joj/src/chapter-listings/node_modules/mjs-mocha/temp/7ajtyl.mjs:149:43
    at Object.callback (file:///home/jahred/Documents/writing/joj/src/chapter-listings/node_modules/mjs-mocha/temp/7ajtyl.mjs:196:20)
    at processLevel (file:///home/jahred/Documents/writing/joj/src/chapter-listings/node_modules/mjs-mocha/temp/7ajtyl.mjs:94:20)
    at processTicksAndRejections (internal/process/task_queues.js:85:5)
    at async processLevel (file:///home/jahred/Documents/writing/joj/src/chapter-listings/node_modules/mjs-mocha/temp/7ajtyl.mjs:110:7) {
  errno: -2,
  syscall: 'open',
  code: 'ENOENT',
  path: '/home/jahred/Documents/writing/joj/src/chapter-listings/src/misc/sample.txt'
}

 ✗ 3/5 failed

  Studies new and instanceof:
{ fromEmail: 'a', toEmail: 'b' }
    ✔ Using new passed
    ✔ Using instanceof passed

 ✔ All 2 tests passed

  OLOO domain modeling:
[ { hash: '0000' } ]
[ { hash: '0000' }, { hash: '234' } ]
true
    ✔ Extends array using OLOO pattern passed
    ✔ Should create a simple Transaction model passed
MY NAME IS LUIS!!
I'm studying compsci
    ✔ Should create a simple Person/Student model passed
Hello, I am Bar:b1.
Hello, I am Bar:b2.
    ✔ Should create a simple Foo/Bar model passed

 ✔ All 4 tests passed

  Parameter validation with default arguments:
    ✔ Uses default argument syntax to provide parameter validation passed
    ✔ Validates the second argument passed
    ✔ Validates the first argument passed

 ✔ All 3 tests passed

 ✗ 4/53 test suites failed
luijar commented 5 years ago

Whoops I was .gitignore-ing the .txt files. I fixed and checked it in. Please do a Git pull and try again. Thanks for letting me know!

Lazarus404 commented 5 years ago

All good, now. Thanks :)