unit.test.js.tpl 1.1 KB

1234567891011121314151617181920212223242526272829303132
  1. import fs from 'fs';
  2. import Promise from 'bluebird';
  3. import { runLoaders } from 'loader-runner';
  4. import { getFixtureResource, getFixture, getLoader } from './test-utils';
  5. const runLoadersPromise = Promise.promisify(runLoaders);
  6. const readFilePromise = Promise.promisify(fs.readFile, { context: fs });
  7. const loaders = getLoader();
  8. describe('Example Loader Tests: Fixture: simple-file', () => {
  9. const fixtureName = 'simple-file';
  10. const resource = getFixture(fixtureName);
  11. test('loaded file should be different', async () => {
  12. const originalSource = await readFilePromise(resource);
  13. const { result } = await runLoadersPromise({ resource: getFixtureResource(fixtureName), loaders });
  14. expect(result).not.toEqual(originalSource);
  15. });
  16. test('loader prepends correct information', async () => {
  17. const { result } = await runLoadersPromise({ resource: getFixtureResource(fixtureName), loaders });
  18. const resultMatcher = expect.arrayContaining([
  19. expect.stringContaining(' * Original Source From Loader'),
  20. ]);
  21. expect(result).toEqual(resultMatcher);
  22. expect(result).toMatchSnapshot();
  23. });
  24. });