namespace.js 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /*
  2. * Jake JavaScript build tool
  3. * Copyright 2112 Matthew Eernisse (mde@fleegix.org)
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. *
  17. */
  18. const PROJECT_DIR = process.env.PROJECT_DIR;
  19. // Load the jake global
  20. require(`${PROJECT_DIR}/lib/jake`);
  21. let { Namespace } = require(`${PROJECT_DIR}/lib/namespace`);
  22. require('./jakefile');
  23. let assert = require('assert');
  24. suite('namespace', function () {
  25. this.timeout(7000);
  26. test('resolve namespace by relative name', function () {
  27. let aaa, bbb, ccc;
  28. aaa = namespace('aaa', function () {
  29. bbb = namespace('bbb', function () {
  30. ccc = namespace('ccc', function () {
  31. });
  32. });
  33. });
  34. assert.ok(aaa, Namespace.ROOT_NAMESPACE.resolveNamespace('aaa'));
  35. assert.ok(bbb === aaa.resolveNamespace('bbb'));
  36. assert.ok(ccc === aaa.resolveNamespace('bbb:ccc'));
  37. });
  38. test('resolve task in sub-namespace by relative path', function () {
  39. let curr = Namespace.ROOT_NAMESPACE.resolveNamespace('zooby');
  40. let task = curr.resolveTask('frang:w00t:bar');
  41. assert.ok(task.action.toString().indexOf('zooby:frang:w00t:bar') > -1);
  42. });
  43. test('prefer local to top-level', function () {
  44. let curr = Namespace.ROOT_NAMESPACE.resolveNamespace('zooby:frang:w00t');
  45. let task = curr.resolveTask('bar');
  46. assert.ok(task.action.toString().indexOf('zooby:frang:w00t:bar') > -1);
  47. });
  48. test('does resolve top-level', function () {
  49. let curr = Namespace.ROOT_NAMESPACE.resolveNamespace('zooby:frang:w00t');
  50. let task = curr.resolveTask('foo');
  51. assert.ok(task.action.toString().indexOf('top-level foo') > -1);
  52. });
  53. test('absolute lookup works from sub-namespaces', function () {
  54. let curr = Namespace.ROOT_NAMESPACE.resolveNamespace('hurr:durr');
  55. let task = curr.resolveTask('zooby:frang:w00t:bar');
  56. assert.ok(task.action.toString().indexOf('zooby:frang:w00t:bar') > -1);
  57. });
  58. test('resolution miss with throw error', function () {
  59. let curr = Namespace.ROOT_NAMESPACE;
  60. let task = curr.resolveTask('asdf:qwer');
  61. assert.ok(!task);
  62. });
  63. });