{"id":26077658,"url":"https://github.com/wallabyjs/wallaby-requirejs-sample","last_synced_at":"2026-04-22T07:36:14.272Z","repository":{"id":27565253,"uuid":"31047364","full_name":"wallabyjs/wallaby-requirejs-sample","owner":"wallabyjs","description":"Testing require.js app with wallaby.js","archived":false,"fork":false,"pushed_at":"2016-03-15T04:34:53.000Z","size":113,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-16T03:42:53.884Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"http://wallabyjs.com","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/wallabyjs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-02-20T02:02:25.000Z","updated_at":"2018-10-20T00:03:33.000Z","dependencies_parsed_at":"2022-09-09T23:24:51.327Z","dependency_job_id":null,"html_url":"https://github.com/wallabyjs/wallaby-requirejs-sample","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/wallabyjs/wallaby-requirejs-sample","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wallabyjs%2Fwallaby-requirejs-sample","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wallabyjs%2Fwallaby-requirejs-sample/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wallabyjs%2Fwallaby-requirejs-sample/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wallabyjs%2Fwallaby-requirejs-sample/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wallabyjs","download_url":"https://codeload.github.com/wallabyjs/wallaby-requirejs-sample/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wallabyjs%2Fwallaby-requirejs-sample/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32126219,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-22T00:31:26.853Z","status":"online","status_checked_at":"2026-04-22T02:00:05.693Z","response_time":58,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-03-09T03:05:27.168Z","updated_at":"2026-04-22T07:36:14.254Z","avatar_url":"https://github.com/wallabyjs.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"Testing require.js code with wallaby.js\n==================================\n\n![screen shot 2015-04-13 at 2 45 02 pm](https://cloud.githubusercontent.com/assets/979966/7109935/b9fd680e-e1eb-11e4-96f1-1d8482efa6e5.png)\n\nTo get Wallaby.js to run with require.js we need two files:\n\n* `wallaby.js` \u0026mdash; which configures wallaby.js\n* `test-main.js` \u0026mdash; which configures require.js for the tests\n\nLet's say our app has a directory structure which looks something like this:\n\n```bash\n$ tree\n.\n|-- index.html\n|-- wallaby.js\n|-- lib\n|   |-- jquery.js\n|   |-- require.js\n|   `-- underscore.js\n|-- src\n|   |-- app.js\n|   `-- main.js\n`-- test\n    |-- appSpec.js\n    `-- test-main.js\n\n3 directories, 9 files\n```\n\n## Configure wallaby.js\n\nThe first step is creating our `wallaby.js`.\n\n```javascript\nmodule.exports = function () {\n  return {\n    files: [\n      {pattern: 'lib/require.js', instrument: false},\n      {pattern: 'lib/*.js', instrument: false, load: false},\n      {pattern: 'src/app.js', load: false},\n      {pattern: 'test/test-main.js', instrument: false}\n    ],\n\n    tests: [\n      {pattern: 'test/appSpec.js', load: false}\n    ]\n  };\n};\n```\n\nPlease notice that we need set `load: false` to all the files and tests except `test/test-main.js`, everything else is loaded by require.js.\n\nIn this example we'll use Jasmine (wallaby.js is using it by default), but other test frameworks works just\nas well.\n\n## Configuring require.js\n\nJust like any require.js project, you need a main module to bootstrap\nyour tests. We do this is `test/test-main.js`.\n\n### Require Each Test File\n\nWith wallaby.js we don't need to list all test files ourselves as we can\neasily find them from the files specified in `test-main.js`: wallaby\nincludes all the files in `window.wallaby.tests`.\n\nNow we can tell Require.js to load our tests, which must be done\nasynchronously as dependencies must be fetched before the tests are run.\nThe `test/test-main.js` file ends up looking like this:\n\n```javascript\n// delaying wallaby automatic start\nwallaby.delayStart();\n\nrequirejs.config({\n  baseUrl: '/src',\n\n  paths: {\n    'jquery': '../lib/jquery',\n    'underscore': '../lib/underscore'\n  },\n\n  shim: {\n    'underscore': {\n      exports: '_'\n    }\n  }\n});\n\nrequire(wallaby.tests, function () {\n  wallaby.start();\n});\n\n```\n\n## Using Require.js in tests\n\nTests can now be written as regular Require.js modules. We wrap\neverything in `define`, and inside we can use the regular test methods,\nsuch as `describe` and `it`. Example:\n\n```javascript\ndefine(['app', 'jquery', 'underscore'], function(App, $, _) {\n\n    describe('just checking', function() {\n\n        it('works for app', function() {\n            var el = $('\u003cdiv\u003e\u003c/div\u003e');\n\n            var app = new App(el);\n            app.render();\n\n            expect(el.text()).toEqual('require.js up and running');\n        });\n\n        it('works for underscore', function() {\n            // just checking that _ works\n            expect(_.size([1,2,3])).toEqual(3);\n        });\n\n    });\n\n});\n```\n---\n\nBased on [Karma with require.js repository](https://github.com/kjbekkelund/karma-requirejs), with some wallaby specific changes.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwallabyjs%2Fwallaby-requirejs-sample","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwallabyjs%2Fwallaby-requirejs-sample","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwallabyjs%2Fwallaby-requirejs-sample/lists"}