it('URL parameters', () => {
        const urlWithQuery = guessResourceType({ url: 'http://example.com/file.css?v=1.0.2' });
        const urlWithHash = guessResourceType({ url: 'http://example.com/file.css#v=1.0.2' });

        assert.deepEqual(urlWithQuery, 'css');
        assert.deepEqual(urlWithHash, 'css');
      });
Example #2
0
  /**
   * The key or value to find the object at a given location
   * @param {number}   index
   * @param {object}  operation object
   * @param {number}  type 0:return key 1:return value
   * @return {string} return object key
   */
  findKeyByIndex(index,object,type = 0){
    assert.strictEqual('number',typeof index,"type error! first parameter must be a number");
    assert.strictEqual('object',typeof object,"type error! second parameter must be a object");
    assert.strictEqual('number',typeof type,"type error! thirdly parameter must be a number");
    let num = 0;
    let result = '';
    for(let k in object){
      if(num === index){
        if(type === 0){
          result = k;
        }else if(type === 1){
          result = object[k];
        }else{
          assert.fail('thirdly parameter Optional type 0 or 1 please read api DOC');
        }
        break;
      }
      num++;
    }

    if(result === '' && num != 0){
      assert.fail('index out of range length is '+num);
    }else{
      return result;
    }
  }
      it('css', () => {
        const cssUrl1 = guessResourceType({ url: 'http://example.com/file.css' });
        const cssUrl2 = guessResourceType({ url: 'http://example.com/STYLES.CSS' });

        assert.deepEqual(cssUrl1, 'css');
        assert.deepEqual(cssUrl2, 'css');
      });
      it('NOT .forbidden', () => {
        const forbiddenUrl1 = guessResourceType({ url: 'http://example.com/file.forbidden' });
        const forbiddenUrl2 = guessResourceType({ url: 'http://example.com/file..forbidden' });

        assert.deepEqual(forbiddenUrl1, null);
        assert.deepEqual(forbiddenUrl2, null);
      });
Example #5
0
 it('should isolate package from preload bundle', async function() {
   const { name, version } = porter.package
   const { text: preloadText } = await requestPath(`/${name}/${version}/preload.js`)
   assert.ok(preloadText.includes(`define("${name}/${version}/preload.js"`))
   const reactDom = porter.package.find({ name: 'react-dom' })
   assert.ok(!preloadText.includes(`define("react-dom/${reactDom.version}/${reactDom.main}"`))
 })
 test(prest, function() {
     var plusgarbage = p[1].concat([5, 98, 23, 244]);
     assert.strict.deepEqual({n: Buffer.from(p[1])},
         match(patternrest, Buffer.from(plusgarbage)));
     assert.strict.deepEqual({n: Buffer.from(p[1])},
         cpatternrest(Buffer.from(plusgarbage)));
 });
Example #7
0
 it('should isolate package from entry bundle', async function() {
   const { name, version } = porter.package
   const { text: mainText } = await requestPath(`/${name}/${version}/home.js?main`)
   // expect(mainText).to.contain('define') hangs if test fails
   assert.ok(mainText.includes(`define("${name}/${version}/home.js"`))
   const react = porter.package.find({ name: 'react' })
   assert.ok(!mainText.includes(`define("react/${react.version}/${react.main}"`))
 })
      it('js', () => {
        const jsCt1 = guessResourceType({ ct: 'text/javascript' });
        const jsCt2 = guessResourceType({ ct: 'application/javascript' });
        const jsCt3 = guessResourceType({ ct: 'application/x-javascript' });

        assert.deepEqual(jsCt1, 'js');
        assert.deepEqual(jsCt2, 'js');
        assert.deepEqual(jsCt3, 'js');
      });
Example #9
0
  it("should bundle preload's dependencies", async function() {
    const { name, version } = porter.package
    const res = await requestPath(`/${name}/${version}/preload.js`)
    assert.ok(res.text.includes(`define("${name}/${version}/preload.js`))

    // yen is bundled
    const yen = porter.package.find({ name: 'yen' })
    assert.ok(res.text.includes(`define("yen/${yen.version}/${yen.main}`))
  })
Example #10
0
 /**
  * The object that specifies the key is promoted one level
  * @param {string} parentKey parent key
  * @param {string} childKey child
  * @param {object} operation object
  * @param {bool} isdelete default:false
  * @return {object} modify object
  */
  levelObjectByKey(parentKey,childKey,object,del = false){
    assert.strictEqual('string',typeof parentKey,"type error! first parameter must be a array or string");
    assert.strictEqual('string',typeof childKey,"type error! first parameter must be a array or string");
    assert.strictEqual('object',typeof object,"type error! second parameter must be a object");
    var obj = this.findObjectByKey(parentKey,object);
    if(del){
      delete object[parentKey];
    }
    object[childKey] = obj[childKey];
    return object;
  }
Example #11
0
      it('.forbidden', () => {
        const forbiddenCt1 = guessResourceType({ ct: 'text/plain' });
        const forbiddenCt2 = guessResourceType({ ct: 'text/xml' });
        const forbiddenCt3 = guessResourceType({ ct: 'application/octet-stream' });
        const forbiddenCt4 = guessResourceType({ ct: 'application/xml' });

        assert.deepEqual(forbiddenCt1, '.forbidden');
        assert.deepEqual(forbiddenCt2, '.forbidden');
        assert.deepEqual(forbiddenCt3, '.forbidden');
        assert.deepEqual(forbiddenCt4, '.forbidden');
      });
Example #12
0
  it('should bundle all dependencies unless preloaded', async function() {
    const { name, version } = porter.package
    const res = await requestPath(`/${name}/${version}/home.js?main`)
    assert.ok(res.text.includes(`define("${name}/${version}/home.js"`))

    // jquery is bundled
    const jquery = porter.package.find({ name: 'jquery' })
    assert.ok(res.text.includes(`define("jquery/${jquery.version}/${jquery.main}`))

    // react is required by `preload.js` already, hence it should not be bundled here.
    const react = porter.package.find({ name: 'react' })
    assert.ok(!res.text.includes(`define("react/${react.version}/${react.main}`))
  })
Example #13
0
 /**
  * Specifies the key array lookup and return object
  * @param {array or string} key array or single key string
  * @param {object} operation object
  * @return {object} found object or value
  */
 findObjectByKeys(keys,object){
   // assert.strictEqual('object',typeof object,"type error! second parameter must be a object");
   let array = [];
   if(typeof keys === 'string'){
     array = [keys];
   }else if(Array.isArray(keys)){
     array = keys;
   }else{
     //Unrecognized parameter type
     assert.strictEqual(1,2,"type error! first parameter must be a array or string");
     // return false;
   }
   let obj = object[array[0]];
   array.splice(0, 1);
   if(obj){
     if(array.length <= 0){
       //found tag and return
       return obj;
     }else{
       return this.findObjectByKeys(array,obj);
     }
   }else{
     return false;  //not found key
   }
 }
Example #14
0
database(':memory:').then(db => {                   // <2>
  const route = configRoute(db);                    // <3>
  assert.deepEqual(typeof route, 'function');       // <4>
  /*
  assert.deepEqual(route(request, response));       // <5>
  */
});
Example #15
0
		.on('error', ({message}) => {
			assert.equal(
				message,
				'Expected a stream created by gulp-gh-pages to receive Vinyl objects https://github.com/gulpjs/vinyl, but got <Buffer 3f>.'
			);

			done();
		})
Example #16
0
    it('Invalid content-type', () => {
      const pdfCt1 = guessResourceType({
        ct: 'invalid/type',
        url: 'http://example.com'
      });

      assert.deepEqual(pdfCt1, null);
    });
Example #17
0
		.on('end', async () => {
			assert.equal(
				await readRemoveFile(join(__dirname, '__cache__', tmpStr), 'utf8'),
				tmpStr
			);

			done();
		})
Example #18
0
		.on('error', ({message}) => {
			assert.equal(
				message,
				'gulp-gh-pages doesn\'t support gulp <= v3.x. Update your project to use gulp >= v4.0.0.'
			);

			done();
		})
Example #19
0
	syntax.Walk(f, function(node) {
		var typ = syntax.NodeType(node)
		if (node == null) {
			nilCount++
			assert.equal(typ, "nil")
		} else {
			nonNilCount++
			if (node.Value == "bar") {
				seenBar = true
			}
			assert.notEqual(typ, "nil")
		}
		if (typ == "CallExpr") {
			seenCall = true
		}
		return true
	})
Example #20
0
    it('Content-type over extension', () => {
      const cssUrl2 = guessResourceType({
        ct: 'text/css',
        url: 'https://example.com/file.min.js'
      });

      assert.deepEqual(cssUrl2, 'css');
    });
Example #21
0
  it('should be mutually exclusive', async function() {
    const { name, version } = porter.package
    const { text: mainText } = await requestPath(`/${name}/${version}/home.js?main`)
    const mainIds = mainText.match(/define\("([^"]+)"/g)
    const { text: preloadText } = await requestPath(`/${name}/${version}/preload.js`)
    const preloadIds = preloadText.match(/define\("([^"]+)"/g)

    for (const id of mainIds) assert.ok(!preloadIds.includes(id))
  })
Example #22
0
exports.decode = function(bson, textures) {
	assert.strict.equal(bson[C.REPO_NODE_LABEL_TYPE], C.REPO_NODE_TYPE_MATERIAL, "Trying to convert " + bson[C.REPO_NODE_LABEL_TYPE] + " to material");

	// Supported only a single diffuse texture per material at the moment.
	if (bson[C.REPO_NODE_LABEL_CHILDREN]) {
		for (let i = 0; i < bson[C.REPO_NODE_LABEL_CHILDREN].length; ++i) {
			const childIDbytes = bson[C.REPO_NODE_LABEL_CHILDREN][i][C.REPO_NODE_LABEL_ID].buffer;
			const childID = UUID.unparse(childIDbytes);
			const texture = textures[childID];
			if (texture) {
				bson.diffuseTexture = childID;
				break;
			}
		}
	}
	return bson;
};
Example #23
0
    it('Empty path', () => {
      const jsUrl4 = guessResourceType({ url: 'https://example.com' });

      assert.deepEqual(jsUrl4, null);
    });
Example #24
0
    it('Missing extension', () => {
      const jsUrl3 = guessResourceType({ url: 'https://example.com/file' });

      assert.deepEqual(jsUrl3, null);
    });
Example #25
0
    it('Invalid extension', () => {
      const jsUrl2 = guessResourceType({ url: 'https://example.com/file.ZZZ' });

      assert.deepEqual(jsUrl2, null);
    });
Example #26
0
      it('js', () => {
        const jsUrl1 = guessResourceType({ url: 'https://example.com/file.min.js' });

        assert.deepEqual(jsUrl1, 'js');
      });
Example #27
0
      it('css', () => {
        const cssCt1 = guessResourceType({ ct: 'text/css' });

        assert.deepEqual(cssCt1, 'css');
      });
Example #28
0
 route({params: {id: 1}}, response).then(() => {
   assert.ok(sendFake.called);
 });
Example #29
0
 route({params: {id: 4}}, response).then(() => {   // <2>
   assert.ok(statusSpy.calledWith(404));           // <3>
   assert.ok(sendFake.calledWith('Livre inconnu'));// <4>
 });
Example #30
0
 test(p[0], function() {
     assert.strict.deepEqual({n: tc[1]}, cpattern(Buffer.from(tc[0])));
 });