<commit_before>/*global yaajs*/
define(function(require, exports, module) {
  var simple = require('data/simple-plugin!./flux');

  var ctx = module.ctx;
  var Module = module.constructor;

  return function (expect) {

    describe(module.id, function () {
      afterEach(function () {
        ctx.constructor.remove("my ctx");
      });

      it("uses normalizeId by default", function () {
        expect(simple).to.be("simple flux");
      });

      it("handles errors", function (done) {
        var myCtx = new ctx.constructor({context: 'my ctx', baseUrl: ctx.baseUrl});
        myCtx.require('data/error-plugin!foo', function () {
          done(new Error("unexpected"));
        }, function (error) {
          try {
            expect(error.message).to.be("Module: data/error-plugin!foo - foo");
            done();
          } catch(ex) {
            done(ex);
          }
        });
      });

      it("can double require a plugin", function (done) {
        var myCtx = new ctx.constructor({context: 'my ctx', baseUrl: ctx.baseUrl});
        var count = 2;
        myCtx.require('data/simple-plugin!foo', assertOk);

        myCtx.require('data/simple-plugin!foo', assertOk);

        function assertOk(result) {
          try {
            expect(result).to.be("simple foo");
            --count || done();
          }
          catch (ex) {
            done(ex);
          }
        }

      });

      it("maps un-normalized correctly", function () {
        var myCtx = new ctx.constructor({context: 'my ctx', baseUrl: ctx.baseUrl});
        var pmod = new Module(myCtx, 'foo');
        var caller = new Module(myCtx, 'baz');
        var loadCount = 0;
        pmod.exports = {load: function (name, req, onLoad) {
          ++loadCount;
        }};
        var plugin = new Module.Plugin(pmod);
        var myMod = plugin.fetch("./unnorm", caller);
        var myMod2 = plugin.fetch("unnorm");
        expect(myCtx.resolvingCount).to.be(4);
        expect(myMod.id).to.equal('');
        expect(plugin.waiting['baz']['./unnorm'][0]).to.be(caller);
        expect(plugin.waiting['baz']['./unnorm'][1]).to.be(myMod);
        expect(plugin.waiting['']['unnorm'][0]).to.be(undefined);
        expect(plugin.waiting['']['unnorm'][1]).to.be(myMod2);

        plugin.ready();

        expect(loadCount).to.equal(1);

        expect(myCtx.resolvingCount).to.equal(4);
        expect(myCtx.depCount).to.equal(0);
      });

      it("calls callbacks", function (done) {
        var myCtx = new ctx.constructor({context: 'my ctx', baseUrl: ctx.baseUrl});
        var waitCount = 2;
        myCtx.require('data/foo-plugin!junk/here/fuzz', function (fuzz) {
          try {
            expect(fuzz).to.eql("hello fuzz");
            --waitCount || done();
          } catch(ex) {
            done(ex);
          }
        }, done);

        myCtx.require('data/foo-plugin', function (plugin) {
          var oCtx = Module.currentCtx;
          try {
            Module.currentCtx = myCtx;
            define("foo5", ['data/foo-plugin!fuzz'], function (fuzz1) {
              try {
                expect(fuzz1).to.eql("hello fuzz");
                expect(Module.currentCtx).to.be(myCtx);
                --waitCount || done();
              } catch(ex) {
                done(ex);
              }
            });
            var fuzz = myCtx.modules['data/foo-plugin!fuzz'];
            fuzz.delayLoad();
          } finally {
            Module.currentCtx = oCtx;
          }
        });
      });
    });
  };
});
<commit_msg>test unloads on error<commit_after>/*global yaajs*/
define(function(require, exports, module) {
  var simple = require('data/simple-plugin!./flux');

  var ctx = module.ctx;
  var Module = module.constructor;

  return function (expect) {

    describe(module.id, function () {
      afterEach(function () {
        ctx.constructor.remove("my ctx");
      });

      it("uses normalizeId by default", function () {
        expect(simple).to.be("simple flux");
      });

      it("handles errors", function (done) {
        var myCtx = new ctx.constructor({context: 'my ctx', baseUrl: ctx.baseUrl});
        myCtx.require('data/error-plugin!foo', function () {
          done(new Error("unexpected"));
        }, function (error) {
          try {
            expect(error.message).to.be("Module: data/error-plugin!foo - foo");
            setTimeout(function () {
              try {
                expect(myCtx.modules['data/error-plugin!foo']).to.be(undefined);
                done();
              } catch(ex) {
                done(ex);
              }
            }, 0);
          } catch(ex) {
            done(ex);
          }
        });
      });

      it("can double require a plugin", function (done) {
        var myCtx = new ctx.constructor({context: 'my ctx', baseUrl: ctx.baseUrl});
        var count = 2;
        myCtx.require('data/simple-plugin!foo', assertOk);

        myCtx.require('data/simple-plugin!foo', assertOk);

        function assertOk(result) {
          try {
            expect(result).to.be("simple foo");
            --count || done();
          }
          catch (ex) {
            done(ex);
          }
        }

      });

      it("maps un-normalized correctly", function () {
        var myCtx = new ctx.constructor({context: 'my ctx', baseUrl: ctx.baseUrl});
        var pmod = new Module(myCtx, 'foo');
        var caller = new Module(myCtx, 'baz');
        var loadCount = 0;
        pmod.exports = {load: function (name, req, onLoad) {
          ++loadCount;
        }};
        var plugin = new Module.Plugin(pmod);
        var myMod = plugin.fetch("./unnorm", caller);
        var myMod2 = plugin.fetch("unnorm");
        expect(myCtx.resolvingCount).to.be(4);
        expect(myMod.id).to.equal('');
        expect(plugin.waiting['baz']['./unnorm'][0]).to.be(caller);
        expect(plugin.waiting['baz']['./unnorm'][1]).to.be(myMod);
        expect(plugin.waiting['']['unnorm'][0]).to.be(undefined);
        expect(plugin.waiting['']['unnorm'][1]).to.be(myMod2);

        plugin.ready();

        expect(loadCount).to.equal(1);

        expect(myCtx.resolvingCount).to.equal(4);
        expect(myCtx.depCount).to.equal(0);
      });

      it("calls callbacks", function (done) {
        var myCtx = new ctx.constructor({context: 'my ctx', baseUrl: ctx.baseUrl});
        var waitCount = 2;
        myCtx.require('data/foo-plugin!junk/here/fuzz', function (fuzz) {
          try {
            expect(fuzz).to.eql("hello fuzz");
            --waitCount || done();
          } catch(ex) {
            done(ex);
          }
        }, done);

        myCtx.require('data/foo-plugin', function (plugin) {
          var oCtx = Module.currentCtx;
          try {
            Module.currentCtx = myCtx;
            define("foo5", ['data/foo-plugin!fuzz'], function (fuzz1) {
              try {
                expect(fuzz1).to.eql("hello fuzz");
                expect(Module.currentCtx).to.be(myCtx);
                --waitCount || done();
              } catch(ex) {
                done(ex);
              }
            });
            var fuzz = myCtx.modules['data/foo-plugin!fuzz'];
            fuzz.delayLoad();
          } finally {
            Module.currentCtx = oCtx;
          }
        });
      });
    });
  };
});

{'fraction_non_alphanumeric': 0.1645933014354067, 'fraction_numerical': 0.004511278195488722, 'mean_word_length': 1.8378588052754072, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3176183', 'n_tokens_mistral': 2206, 'n_tokens_neox': 2202, 'n_words': 395}