Exemplo n.º 1
0
    it('should add the targets of all external outgoing relations as unloaded Asset instances once the asset is loaded', async function() {
      const assetGraph = new AssetGraph();
      const cssAsset = assetGraph.addAsset({
        type: 'Css',
        url: 'https://example.com/styles.css'
      });

      httpception({
        request: 'GET https://example.com/styles.css',
        response: {
          headers: {
            'Content-Type': 'text/css'
          },
          body: 'body { background-image: url(https://example.com/foo.png); }'
        }
      });

      await cssAsset.load();

      expect(assetGraph, 'to contain asset', {
        type: 'Png',
        url: 'https://example.com/foo.png',
        isLoaded: false
      });
    });
Exemplo n.º 2
0
  it('should handle an http: url', async function() {
    httpception({
      request: 'GET http://www.example.com/foo.gif',
      response: {
        statusCode: 200,
        headers: {
          'Content-Type': 'image/gif'
        },
        body: Buffer.from('GIF')
      }
    });

    const assetGraph = new AssetGraph();
    const asset = assetGraph.addAsset('http://www.example.com/foo.gif');
    assetGraph.addAsset(asset);
    await asset.load();
    expect(asset, 'to be an object');
    expect(asset.url, 'to equal', 'http://www.example.com/foo.gif');
    expect(asset.type, 'to equal', 'Gif');
  });