web 3d图形渲染器
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

66 lines
3.4 KiB

  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. const assert = require("assert");
  4. const sinon = require("sinon");
  5. const fs_macchiato_1 = require("../../../fs.macchiato");
  6. const settings_1 = require("../settings");
  7. const provider = require("./sync");
  8. describe('Providers → Sync', () => {
  9. describe('.read', () => {
  10. it('should return lstat for non-symlink entry', () => {
  11. const lstatSync = sinon.stub().returns(new fs_macchiato_1.Stats());
  12. const settings = new settings_1.default({
  13. fs: { lstatSync }
  14. });
  15. const actual = provider.read('filepath', settings);
  16. assert.strictEqual(actual.ino, 0);
  17. });
  18. it('should return lstat for symlink entry when the "followSymbolicLink" option is disabled', () => {
  19. const lstatSync = sinon.stub().returns(new fs_macchiato_1.Stats({ isSymbolicLink: true }));
  20. const settings = new settings_1.default({
  21. followSymbolicLink: false,
  22. fs: { lstatSync }
  23. });
  24. const actual = provider.read('filepath', settings);
  25. assert.strictEqual(actual.ino, 0);
  26. });
  27. it('should return stat for symlink entry', () => {
  28. const lstatSync = sinon.stub().returns(new fs_macchiato_1.Stats({ isSymbolicLink: true }));
  29. const statSync = sinon.stub().returns(new fs_macchiato_1.Stats({ ino: 1 }));
  30. const settings = new settings_1.default({
  31. fs: { lstatSync, statSync }
  32. });
  33. const actual = provider.read('filepath', settings);
  34. assert.strictEqual(actual.ino, 1);
  35. });
  36. it('should return marked stat for symlink entry when the "markSymbolicLink" option is enabled', () => {
  37. const lstatSync = sinon.stub().returns(new fs_macchiato_1.Stats({ isSymbolicLink: true }));
  38. const statSync = sinon.stub().returns(new fs_macchiato_1.Stats({ ino: 1 }));
  39. const settings = new settings_1.default({
  40. markSymbolicLink: true,
  41. fs: { lstatSync, statSync }
  42. });
  43. const actual = provider.read('filepath', settings);
  44. assert.strictEqual(actual.isSymbolicLink(), true);
  45. });
  46. it('should return lstat for broken symlink entry when the "throwErrorOnBrokenSymbolicLink" option is disabled', () => {
  47. const lstatSync = sinon.stub().returns(new fs_macchiato_1.Stats({ isSymbolicLink: true }));
  48. const statSync = sinon.stub().throws(new Error('error'));
  49. const settings = new settings_1.default({
  50. fs: { lstatSync, statSync },
  51. throwErrorOnBrokenSymbolicLink: false
  52. });
  53. const actual = provider.read('filepath', settings);
  54. assert.strictEqual(actual.ino, 0);
  55. });
  56. it('should throw an error when symlink entry is broken', () => {
  57. const lstatSync = sinon.stub().returns(new fs_macchiato_1.Stats({ isSymbolicLink: true }));
  58. const statSync = sinon.stub().throws(new Error('broken'));
  59. const settings = new settings_1.default({
  60. fs: { lstatSync, statSync }
  61. });
  62. const expectedErrorMessageRe = /broken/;
  63. assert.throws(() => provider.read('filepath', settings), expectedErrorMessageRe);
  64. });
  65. });
  66. });