Backend Project Tests - Sudoku Solver and Am/Brit Translator - Not possible to test from fCC side
See original GitHub issueDescribe your problem and how to reproduce it: I have been working on #37185 (Add Tests for Backend Projects) as I’ve worked though the QA curriculum. I have evaluated the user stories for the Sudoku Solver and American-British Translator and determined that it is not possible to create an FCC hosted test for these projects with any degree of coverage.
The problem is that these two projects are effectively “frontend” projects. Neither has an API nor any significant server-side content. All of the user interaction takes place on the UI, typically in response to user interaction via event handlers.
What I explored
During the time I spent attempting to write my personal unit/functional tests for Sudoku Solver I explored a number of possibilities to enable virtual DOM/headless testing of functional interactions.
JSDOM (current solution) Lacks the ability to trigger events or, if it’s possible, I was unable to get it to work with my code. I tried manually injecting events, but they never fired my handlers. Even if this did work, while it is theoretically possible to run JSDOM natively in the client, doing so opens up the very real possibility of XSS attacks on a user’s fCC profile, assuming we could overcome the CORS issues.
On the server hosted tests I was able to make this work by exporting and manually executing individual handler functions, but only for the unit testing. I was unable to make the Functional tests run with jsdom as they require events to trigger.
Zombie.js
I had no better luck getting events to trigger with Zombie.js. The same client-side security issues potentially exist.
Puppeteer (Server Side Only) I ultimately used Puppeteer for functional testing - this launches a headless version of Chrome and programmatically simulates user interaction. I don’t think this would scale well for fCC hosting testing.
Possible Solutions
- Write two new modules for the front-end testing framework. This is straightforward to do. It just suffers from the same “honor system” issues that all of the font-end projects have.
- Rewrite these projects as backend with an API. This would be more in the spirit of being more back-end focused. It would reduce the scope of the project somewhat. Having to face the issues of testing with a virtual DOM and/or headless browser are valuable lessons. It would also be silly to put some of the functionality server-side (like character validation).
- Update the fCC tests to just check the
/_api/get-testsend point and parse forpassedon various tests. This would require changing the user stories which are displayed on the fCC landing pages to more closely match the verbiage found in the1_unit-tests.jsand2_functional-tests.jsfiles. This might create some confusion? It is also only slightly better than the “honor system”, although it’s slightly harder to fake that output if we’re counting assertions.
Issue Analytics
- State:
- Created 3 years ago
- Comments:26 (26 by maintainers)

Top Related StackOverflow Question
This morning I met with @nhcarrigan and @Sky020 on Discord and we had a detailed discussion about the Sudoku Solver project, in an effort to move it to a more back-end focused project, as discussed in this thread.
We came up with a new concept for the solver which will focus more on understanding the algorithm enough to test it properly by adding a new endpoint
/api/checkwhich takes a puzzle, coordinate, and value and determines if it is a valid placement. This seems to be in line with the sort of functionality that an interactive Sudoku solve might have and aligns closely with the goals of the “Quality Assurance” section.This would also result in a more minimalist front-end which checks the two routes separately. It would have a bit more fCC supplied code to enable the grid->text and text->grid movement, but that’s more of a convivence for the tester then a “feature” of the project and we won’t test for it.
User Stories
POST/api/solvewith form data containing puzzle which will consist of the text representation of a puzzle. The returned object will containsolutionwith the solved puzzle.puzzle, the returned value will be{ error: 'Required field missing' }{ error: 'Invalid characters in puzzle' }{ error: 'Expected puzzle to be 81 characters long' }{ error: 'Puzzle cannot be solved' }POSTto/api/checkan object containingpuzzle,coordinate, andvaluewhere thecoordinateis the letter A-I followed by a number 1-9 and thevalueis a number from 1-9.valid, which istrueif the number may be placed at the provided coordinate andfalseif the number may not. If false, the returned object will also containconflictwhich is an array cotaining the strings"row","column", and/or"region"depending on which makes the placement invalid.{ error: 'Invalid characters in puzzle' }{ error: 'Expected puzzle to be 81 characters long' }puzzle,coordinateorvalue, the the returned value will be{ error: 'Required field(s) missing' }{ error: 'Invalid coordinate'}valueis not a number between 1 and 9, the returned values will be{ error: 'Invalid value' }/tests/1_unit-tests.jsfor the expected behavior you should write tests for./tests/2_functional-tests.jsfor the functionality you should write tests for.Boilerplate Functionality
/checkrouteToday @nhcarrigan and I updated the user stories on the Sudoku Solver as you had suggested @moT01. Our expectation is that these will ultimately end up in the
/learntext, but for the moment they’ll live in theREADME.md. The Repl.it and GitHub links above have been updated.We also refactored the American/British Translator project.
Repl.it with code: https://repl.it/@SaintPeter/fcc-american-british-translator-boilerplate-refactor
GitHub Branch: https://github.com/SaintPeter/boilerplate-project-american-british-english-translator/tree/feat/backend-refactor
Note: We do have additional text for the
/learnbody, which is currently parked in theREADME.mdfile.Please advise what our next steps should be. We are prepared to update the
/learnuser stories and write the functional tests. Additionally, we can produce an updated example project which will pass those tests using the new boilerplate framework.