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 19const PROJECT_DIR = process.env.PROJECT_DIR; 20 21// Load the jake global 22require(`${PROJECT_DIR}/lib/jake`); 23let { Namespace } = require(`${PROJECT_DIR}/lib/namespace`); 24 25require('./jakefile'); 26 27let assert = require('assert'); 28 29suite('namespace', function () { 30 31 this.timeout(7000); 32 33 test('resolve namespace by relative name', function () { 34 let aaa, bbb, ccc; 35 aaa = namespace('aaa', function () { 36 bbb = namespace('bbb', function () { 37 ccc = namespace('ccc', function () { 38 }); 39 }); 40 }); 41 42 assert.ok(aaa, Namespace.ROOT_NAMESPACE.resolveNamespace('aaa')); 43 assert.ok(bbb === aaa.resolveNamespace('bbb')); 44 assert.ok(ccc === aaa.resolveNamespace('bbb:ccc')); 45 }); 46 47 test('resolve task in sub-namespace by relative path', function () { 48 let curr = Namespace.ROOT_NAMESPACE.resolveNamespace('zooby'); 49 let task = curr.resolveTask('frang:w00t:bar'); 50 assert.ok(task.action.toString().indexOf('zooby:frang:w00t:bar') > -1); 51 }); 52 53 test('prefer local to top-level', function () { 54 let curr = Namespace.ROOT_NAMESPACE.resolveNamespace('zooby:frang:w00t'); 55 let task = curr.resolveTask('bar'); 56 assert.ok(task.action.toString().indexOf('zooby:frang:w00t:bar') > -1); 57 }); 58 59 test('does resolve top-level', function () { 60 let curr = Namespace.ROOT_NAMESPACE.resolveNamespace('zooby:frang:w00t'); 61 let task = curr.resolveTask('foo'); 62 assert.ok(task.action.toString().indexOf('top-level foo') > -1); 63 }); 64 65 test('absolute lookup works from sub-namespaces', function () { 66 let curr = Namespace.ROOT_NAMESPACE.resolveNamespace('hurr:durr'); 67 let task = curr.resolveTask('zooby:frang:w00t:bar'); 68 assert.ok(task.action.toString().indexOf('zooby:frang:w00t:bar') > -1); 69 }); 70 71 test('resolution miss with throw error', function () { 72 let curr = Namespace.ROOT_NAMESPACE; 73 let task = curr.resolveTask('asdf:qwer'); 74 assert.ok(!task); 75 }); 76 77}); 78