noCache.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. var assert = require("assert");
  2. var requireDir = require("..");
  3. var fs = require("fs");
  4. var cachedResult = {
  5. a: "a",
  6. b: "b"
  7. };
  8. var notCachedResult = {
  9. a: "c",
  10. b: "b"
  11. };
  12. // filter the results to a particular file:
  13. assert.deepEqual(requireDir("./noCache", { noCache: false }), cachedResult);
  14. var promiseFileModification = new Promise(function(resolve, reject) {
  15. fs.writeFile("test/noCache/a.js", "module.exports = 'c';", "ascii", function(
  16. error
  17. ) {
  18. if (error) {
  19. reject(error);
  20. } else {
  21. resolve();
  22. }
  23. });
  24. });
  25. promiseFileModification.then(
  26. function() {
  27. // Check if cache is active that it is the same result
  28. assert.deepEqual(requireDir("./noCache", { noCache: false }), cachedResult);
  29. // Check by removing cache that the result is the new content
  30. assert.deepEqual(
  31. requireDir("./noCache", { noCache: true }),
  32. notCachedResult
  33. );
  34. console.log("noCache tests passed.");
  35. fs.writeFile(
  36. "test/noCache/a.js",
  37. "module.exports = 'a';",
  38. "ascii",
  39. function(error) {
  40. if (error) {
  41. console.error("noCache tests, issue to reset test.");
  42. console.error(error);
  43. }
  44. }
  45. );
  46. },
  47. function(error) {
  48. console.error("noCache tests failed.");
  49. console.error(error);
  50. }
  51. );