1// Copyright 2020 the V8 project authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5/**
6 * @fileoverview Test normalization.
7 */
8
9'use strict';
10
11const sinon = require('sinon');
12
13const helpers = require('./helpers.js');
14const sourceHelpers = require('../source_helpers.js');
15
16const { ScriptMutator } = require('../script_mutator.js');
17
18const sandbox = sinon.createSandbox();
19
20function testLoad(testPath, expectedPath) {
21  const mutator = new ScriptMutator({}, helpers.DB_DIR);
22  const source = helpers.loadTestData(testPath);
23  const dependencies = mutator.resolveInputDependencies([source]);
24  const code = sourceHelpers.generateCode(source, dependencies);
25  helpers.assertExpectedResult(expectedPath, code);
26}
27
28describe('V8 dependencies', () => {
29  it('test', () => {
30    testLoad(
31        'mjsunit/test_load.js',
32        'mjsunit/test_load_expected.js');
33
34  });
35  it('does not loop indefinitely', () => {
36    testLoad(
37        'mjsunit/test_load_self.js',
38        'mjsunit/test_load_self_expected.js');
39  });
40});
41
42describe('Chakra dependencies', () => {
43  it('test', () => {
44    testLoad(
45        'chakra/load.js',
46        'chakra/load_expected.js');
47  });
48});
49
50describe('JSTest dependencies', () => {
51  afterEach(() => {
52    sandbox.restore();
53  });
54
55  it('test', () => {
56    const fakeStubs = sourceHelpers.loadSource(
57        helpers.BASE_DIR, 'JSTests/fake_stub.js');
58    sandbox.stub(sourceHelpers, 'loadResource').callsFake(() => fakeStubs);
59    testLoad('JSTests/load.js', 'JSTests/load_expected.js');
60  });
61});
62
63describe('SpiderMonkey dependencies', () => {
64  it('test', () => {
65    testLoad(
66        'spidermonkey/test/load.js',
67        'spidermonkey/test/load_expected.js');
68  });
69});
70