'use strict'; const helpers = {}; global.hexo = { extend: { helper: { register(name, helper) { helpers[name] = helper; } } } }; require('../../scripts/helpers/engine'); delete global.hexo; describe('engine', () => { const context = { next_version: '8.28.0', theme : { js : 'js', vendors: { internal : 'local', custom_cdn_url: '', library : { url: 'https://cdn.example.com/library.js' }, secure_library: { url : 'https://cdn.example.com/secure.js', integrity: 'sha256-example' }, stylesheet: { url: 'https://cdn.example.com/library.css' } } }, url_for(path) { return '/' + path; } }; const nextJs = helpers.next_js.bind(context); const nextVendors = helpers.next_vendors.bind(context); it('keeps defer as the default for NexT scripts', () => { nextJs('main.js').should.eql(''); }); it('supports custom loading options for NexT scripts', () => { nextJs('main.js', { defer: false }).should.eql(''); nextJs('main.js', { async: true }).should.eql(''); nextJs('main.js', { defer: true, async: true }).should.eql(''); }); it('preserves existing NexT script options', () => { nextJs('main.js', { pjax: true, module: true }).should.eql(''); }); it('keeps defer as the default for vendor scripts', () => { nextVendors('library').should.eql(''); nextVendors('secure_library').should.eql(''); }); it('supports custom loading options for vendor scripts', () => { nextVendors('library', { defer: false }).should.eql(''); nextVendors('library', { async: true }).should.eql(''); }); it('does not apply script loading options to stylesheets', () => { nextVendors('stylesheet', { async: true }).should.eql(''); }); });