<fim-prefix>']);
				done();
			}).catch(done);
		});
	});

	describe('leaves()', () => {
		it('returns modules that have no dependencies', (done) => {
			madge(__dirname + '/cjs/normal').then((res) => {
				res.leaves().should.eql(['d.js']);
				done();
			}).catch(done);
		});
	});

	describe('svg()', () => {
		it('returns a promise resolved with XML SVG output in a Buffer', (done) => {
			madge(__dirname + '/cjs/b.js')
				.then((res) => res.svg())
				.then((output) => {
					output.should.instanceof(Buffer);
					output.toString().should.match(/<svg.*/);
					done();
				})
				.catch(done);
		});
	});

	describe('image()', () => {
		let imagePath;

		beforeEach(() => {
			imagePath = path.join(os.tmpdir(), 'madge_' + Date.now() + '_image.png');
		});

		afterEach(() => {
			return fs.unlink(imagePath).catch(() => {});
		});

		it('rejects if a filename is not supplied', (done) => {
			madge(__dirname + '/cjs/a.js')
				.then((res) => res.image())
				.catch((err) => {
					err.message.should.eql('imagePath not provided');
					done();
				});
		});

		it('rejects on unsupported image format', (done) => {
			madge(__dirname + '/cjs/a.js')
				.then((res) => res.image('image.zyx'))
				.catch((err) => {
					err.message.should.match(/Format: "zyx" not recognized/);
					done();
				});
		});

		it('rejects if graphviz is not installed', (done) => {
			madge(__dirname + '/cjs/a.js', {graphVizPath: '/invalid/path'})
				.then((res) => res.image('image.png'))
				.catch((err) => {
					// BUG: CWE-89 Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection')
					// err.message.should.match(/Could not execute .*gvpr \-V/);
					// FIXED:
	<fim-middle>				err.message.should.eql('Graphviz could not be found. Ensure that "gvpr" is in your $PATH. Error: spawn /invalid/path/gvpr ENOENT');
					done();
				});
		});

		it('writes image to file', (done) =<fix-suffix>> {
			madge(__dirname + '/cjs/a.js')
				.then((res) => res.image(imagePath))
				.then((writtenImagePath) => {
					writtenImagePath.should.eql(imagePath);

					return fs
						.exists(imagePath)
						.then((exists) => {
							if (!exists) {
								throw new Error(imagePath + ' not created');
							}
							done();
						});
				})
				.catch(done);
		});
	});
});
<|endoftext|>