ronantakizawa/codereview-bench huggingface dataset:
Repository: nodejs/node
File: src/quic/data.cc (C++)

Code before:
  auto length = view->ByteLength();
  auto offset = view->ByteOffset();
  if (!view->Buffer()->Detach(detach_key).To(&res) || !res) {
    return Nothing<Store>();
  }
  return Just(Store(std::move(backing), length, offset));
}

Local<Uint8Array> Store::ToUint8Array(Environment* env) const {
  return !store_
             ? Uint8Array::New(ArrayBuffer::New(env->isolate(), 0), 0, 0)
             : Uint8Array::New(
                   ArrayBuffer::New(env->isolate(), store_), offset_, length_);
}

Store::operator bool() const {
  return store_ != nullptr;
}
size_t Store::length() const {
  return length_;
}

size_t Store::total_length() const {
  return store_ ? store_->ByteLength() : 0;
}

template <typename T, OneByteType N>
T Store::convert() const {
  // We can only safely convert to T if we have a valid store.
  CHECK(store_);
  T buf;
  buf.base =
      store_ != nullptr ? static_cast<N*>(store_->Data()) + offset_ : nullptr;
  buf.len = length_;
  return buf;
}

Store::operator uv_buf_t() const {
  return convert<uv_buf_t, char>();
}

Store::operator ngtcp2_vec() const {
  return convert<ngtcp2_vec, uint8_t>();
}

Store::operator nghttp3_vec() const {
  return convert<nghttp3_vec, uint8_t>();
}

void Store::MemoryInfo(MemoryTracker* tracker) const {
  tracker->TrackField("store", store_);

Review comment (bug):
Would be nice if we could handle allocation failures in these calls too

Code after:
  auto length = view->ByteLength();
  auto offset = view->ByteOffset();
  if (!view->Buffer()->Detach(detach_key).To(&res) || !res) {
    return Nothing<Store>();
  }
  return Just(Store(std::move(backing), length, offset));
}

Store Store::CopyFrom(Local<ArrayBuffer> buffer) {
  v8::Isolate* isolate = v8::Isolate::GetCurrent();
  auto backing = buffer->GetBackingStore();
  auto length = buffer->ByteLength();
  auto dest = ArrayBuffer::NewBackingStore(
      isolate, length, v8::BackingStoreInitializationMode::kUninitialized);
  // copy content
  memcpy(dest->Data(), backing->Data(), length);
  return Store(std::move(dest), length, 0);
}

Store Store::CopyFrom(Local<ArrayBufferView> view) {
  v8::Isolate* isolate = v8::Isolate::GetCurrent();
  auto backing = view->Buffer()->GetBackingStore();
  auto length = view->ByteLength();
  auto offset = view->ByteOffset();
  auto dest = ArrayBuffer::NewBackingStore(
      isolate, length, v8::BackingStoreInitializationMode::kUninitialized);
  // copy content
  memcpy(dest->Data(), static_cast<char*>(backing->Data()) + offset, length);
  return Store(std::move(dest), length, 0);
}

Local<Uint8Array> Store::ToUint8Array(Environment* env) const {
  return !store_
             ? Uint8Array::New(ArrayBuffer::New(env->isolate(), 0), 0, 0)
             : Uint8Array::New(
                   ArrayBuffer::New(env->isolate(), store_), offset_, length_);
}

Store::operator bool() const {
  return store_ != nullptr;
}
size_t Store::length() const {
  return length_;
}

size_t Store::total_length() const {
  return store_ ? store_->ByteLength() : 0;
}

template <typename T, OneByteType N>
T Store::convert() const {
Repository: nodejs/node
File: lib/internal/process/execution.js (JavaScript)

Code before:
      globalThis.exports = exports;
      globalThis.__dirname = __dirname;
      globalThis.require = require;
      return (main) => main();
    `;
  globalThis.__filename = name;
  RegExpPrototypeExec(/^/, ''); // Necessary to reset RegExp statics before user code runs.
  const result = module._compile(script, `${name}-wrapper`)(() => {
    // If the script was already compiled, use it.
    return runScriptInThisContext(
      compiledScript ?? compileScript(name, body, baseUrl),
      true, !!breakFirstLine);
  });
  if (print) {
    const { log } = require('internal/console/global');
    let printed = false;

    process.once('beforeExit', () => {
      printed = true;
      log(result);
    });

    process.once('exit', () => {
      if (!printed)
        log(result);
    });
  }
  if (origModule !== undefined)
    globalThis.module = origModule;
}

module.exports = {
  parseAndEvalCommonjsTypeScript,
  parseAndEvalModuleTypeScript,
  readStdin,
  tryGetCwd,
  evalModuleEntryPoint,
  evalTypeScript,
  evalScript,
  onGlobalUncaughtException: createOnGlobalUncaughtException(),
  setUncaughtExceptionCaptureCallback,
  hasUncaughtExceptionCaptureCallback,
};


Review comment (suggestion):
nit: Would it be clearer to remove the exit handler instead?
```suggestion
    const printHandler = () => log(result);

    process.on('exit', printHandler);
    process.once('beforeExit', () => {
      printHandler();
      process.off('exit', printHandler);
    });
```

Code after:
      globalThis.exports = exports;
      globalThis.__dirname = __dirname;
      globalThis.require = require;
      return (main) => main();
    `;
  globalThis.__filename = name;
  RegExpPrototypeExec(/^/, ''); // Necessary to reset RegExp statics before user code runs.
  const result = module._compile(script, `${name}-wrapper`)(() => {
    // If the script was already compiled, use it.
    return runScriptInThisContext(
      compiledScript ?? compileScript(name, body, baseUrl),
      true, !!breakFirstLine);
  });
  if (print) {
    const { log } = require('internal/console/global');

    const printResult = () => log(result);

    process.on('exit', printResult);
    process.once('beforeExit', () => {
      printResult();
      process.off('exit', printResult);
    });
  }
  if (origModule !== undefined)
    globalThis.module = origModule;
}

module.exports = {
  parseAndEvalCommonjsTypeScript,
  parseAndEvalModuleTypeScript,
  readStdin,
  tryGetCwd,
  evalModuleEntryPoint,
  evalTypeScript,
  evalScript,
  onGlobalUncaughtException: createOnGlobalUncaughtException(),
  setUncaughtExceptionCaptureCallback,
  hasUncaughtExceptionCaptureCallback,
};
Repository: nodejs/node
File: lib/internal/test_runner/reporter/utils.js (JavaScript)

Code before:
    RegExpPrototypeSymbolSplit(
      hardenRegExp(/\r?\n/),
      inspectWithNoCustomRetry(err, inspectOptions),
    ), `\n${indent}  `);
  return `\n${indent}  ${message}\n`;
}

function formatTestReport(type, data, showErrorDetails = true, prefix = '', indent = '') {
  let color = reporterColorMap[type] ?? colors.white;
  let symbol = reporterUnicodeSymbolMap[type] ?? ' ';
  const { skip, todo, expectFailure } = data;
  const duration_ms = data.details?.duration_ms ? ` ${colors.gray}(${data.details.duration_ms}ms)${colors.white}` : '';
  let title = `${data.name}${duration_ms}`;

  if (skip !== undefined) {
    title += ` # ${typeof skip === 'string' && skip.length ? skip : 'SKIP'}`;
    color = colors.gray;
    symbol = reporterUnicodeSymbolMap['hyphen:minus'];
  } else if (todo !== undefined) {
    title += ` # ${typeof todo === 'string' && todo.length ? todo : 'TODO'}`;
    if (type === 'test:fail') {
      color = colors.yellow;
      symbol = reporterUnicodeSymbolMap['warning:alert'];
    }
  } else if (expectFailure !== undefined) {
    title += ` # EXPECTED FAILURE`;
    color = colors.yellow;
    symbol = reporterUnicodeSymbolMap['warning:alert'];
  }

  const err = showErrorDetails && data.details?.error ? formatError(data.details.error, indent) : '';

  return `${prefix}${indent}${color}${symbol}${title}${colors.white}${err}`;
}

module.exports = {
  __proto__: null,
  reporterUnicodeSymbolMap,
  reporterColorMap,
  formatTestReport,
  indent,
};


Review comment (suggestion):
🤔 I think this should be info (and probably grey) not warning: no special attention is appropriate here, it's just an FYI.

Code after:
    RegExpPrototypeSymbolSplit(
      hardenRegExp(/\r?\n/),
      inspectWithNoCustomRetry(err, inspectOptions),
    ), `\n${indent}  `);
  return `\n${indent}  ${message}\n`;
}

function formatTestReport(type, data, showErrorDetails = true, prefix = '', indent = '') {
  let color = reporterColorMap[type] ?? colors.white;
  let symbol = reporterUnicodeSymbolMap[type] ?? ' ';
  const { skip, todo, expectFailure } = data;
  const duration_ms = data.details?.duration_ms ? ` ${colors.gray}(${data.details.duration_ms}ms)${colors.white}` : '';
  let title = `${data.name}${duration_ms}`;

  if (skip !== undefined) {
    title += ` # ${typeof skip === 'string' && skip.length ? skip : 'SKIP'}`;
    color = colors.gray;
    symbol = reporterUnicodeSymbolMap['hyphen:minus'];
  } else if (todo !== undefined) {
    title += ` # ${typeof todo === 'string' && todo.length ? todo : 'TODO'}`;
    if (type === 'test:fail') {
      color = colors.yellow;
      symbol = reporterUnicodeSymbolMap['warning:alert'];
    }
  } else if (expectFailure !== undefined) {
    title += ` # EXPECTED FAILURE`;
  }

  const err = showErrorDetails && data.details?.error ? formatError(data.details.error, indent) : '';

  return `${prefix}${indent}${color}${symbol}${title}${colors.white}${err}`;
}

module.exports = {
  __proto__: null,
  reporterUnicodeSymbolMap,
  reporterColorMap,
  formatTestReport,
  indent,
};
Repository: nodejs/node
File: test/es-module/test-extensionless-esm-type-commonjs.js (JavaScript)

Code before:
'use strict';

const test = require('node:test');
const assert = require('node:assert/strict');
const fs = require('node:fs');
const path = require('node:path');
const { spawnSync } = require('node:child_process');

const tmpdir = require('../common/tmpdir');

test('extensionless entry point with ESM syntax under type=commonjs should not silently exit 0', () => {
  tmpdir.refresh();

  const dir = tmpdir.resolve('extensionless-esm-commonjs');
  fs.mkdirSync(dir, { recursive: true });

  // package.json with type: commonjs
  fs.writeFileSync(
    path.join(dir, 'package.json'),
    '{\n  "type": "commonjs"\n}\n',
    'utf8'
  );

  // Extensionless executable with shebang + ESM syntax.
  // NOTE: Execute via process.execPath to avoid PATH/env differences.
  const scriptPath = path.join(dir, 'script'); // no extension
  fs.writeFileSync(
    scriptPath,
    '#!/usr/bin/env node\n' +
      "console.log('script STARTED')\n" +
      "import { version } from 'node:process'\n" +
      'console.log(version)\n',
    'utf8'
  );
  fs.chmodSync(scriptPath, 0o755);


Review comment (suggestion):
There is no need to use node:test if there is only one test - it would unnecessarily clutter the CI output with nested tap (and if more tests are added they should be in separate files to avoid building test monoliths).

Code after:
'use strict';

require('../common');
const { spawnSyncAndAssert } = require('../common/child_process');
const fixtures = require('../common/fixtures');

spawnSyncAndAssert(process.execPath, [
  fixtures.path('es-modules', 'extensionless-esm-commonjs', 'script'),
], {
  status: 1,
  stderr: /SyntaxError: Cannot use import statement outside a module/,
});

spawnSyncAndAssert(process.execPath, [
  fixtures.path('es-modules', 'extensionless-esm-module', 'script'),
], {
  stdout: /script STARTED[\s\S]*v\d+\./,
  trim: true,
});
Repository: nodejs/node
File: test/es-module/test-extensionless-esm-type-commonjs.js (JavaScript)

Code before:
'use strict';

const fs = require('node:fs');
const path = require('node:path');
const { spawnSyncAndAssert } = require('../common/child_process');
const tmpdir = require('../common/tmpdir');

tmpdir.refresh();

const commonjsDir = tmpdir.resolve('extensionless-esm-commonjs');
fs.mkdirSync(commonjsDir, { recursive: true });

// package.json with type: commonjs
fs.writeFileSync(
  path.join(commonjsDir, 'package.json'),
  '{\n  "type": "commonjs"\n}\n',
  'utf8'
);

// Extensionless executable with shebang + ESM syntax.
// NOTE: Execute via process.execPath to avoid PATH/env differences.
const commonjsScriptPath = path.join(commonjsDir, 'script'); // no extension
fs.writeFileSync(
  commonjsScriptPath,
  '#!/usr/bin/env node\n' +
    "console.log('script STARTED')\n" +
    "import { version } from 'node:process'\n" +
    'console.log(version)\n',
  'utf8'
);
fs.chmodSync(commonjsScriptPath, 0o755);

spawnSyncAndAssert(process.execPath, ['./script'], {
  cwd: commonjsDir,
  encoding: 'utf8',
}, {
  status: 1,
  stderr: /.+/,
  trim: true,

Review comment (bug):
Can you put the two set of test fixtures in folders under test/fixtures and check them into the source instead of generating them on the fly? That would be easier to run directly to debug if they fail. You can use test/common/fixtures.js to read them or resolve the path in the test.

Code after:
'use strict';

require('../common');
const { spawnSyncAndAssert } = require('../common/child_process');
const fixtures = require('../common/fixtures');

spawnSyncAndAssert(process.execPath, [
  fixtures.path('es-modules', 'extensionless-esm-commonjs', 'script'),
], {
  status: 1,
  stderr: /SyntaxError: Cannot use import statement outside a module/,
});

spawnSyncAndAssert(process.execPath, [
  fixtures.path('es-modules', 'extensionless-esm-module', 'script'),
], {
  stdout: /script STARTED[\s\S]*v\d+\./,
  trim: true,
});
Repository: nodejs/node
File: test/es-module/test-extensionless-esm-type-commonjs.js (JavaScript)

Code before:
'use strict';

const { spawnSyncAndAssert } = require('../common/child_process');
const fixtures = require('../common/fixtures');

const commonjsDir = fixtures.path('es-modules', 'extensionless-esm-commonjs');

spawnSyncAndAssert(process.execPath, ['--no-experimental-detect-module', './script'], {
  cwd: commonjsDir,
  encoding: 'utf8',
}, {
  status: 1,
  stderr: /.+/,
  trim: true,
});

const moduleDir = fixtures.path('es-modules', 'extensionless-esm-module');

spawnSyncAndAssert(process.execPath, ['--no-experimental-detect-module', './script'], {
  cwd: moduleDir,
  encoding: 'utf8',
}, {
  stdout: /script STARTED[\s\S]*v\d+\./,
  trim: true,
});


Review comment (bug):
Hmm, why is `--no-experimental-detect-module` needed here? I think the original issue is that it fails by default (without this flag)?

Code after:
'use strict';

require('../common');
const { spawnSyncAndAssert } = require('../common/child_process');
const fixtures = require('../common/fixtures');

spawnSyncAndAssert(process.execPath, [
  fixtures.path('es-modules', 'extensionless-esm-commonjs', 'script'),
], {
  status: 1,
  stderr: /SyntaxError: Cannot use import statement outside a module/,
});

spawnSyncAndAssert(process.execPath, [
  fixtures.path('es-modules', 'extensionless-esm-module', 'script'),
], {
  stdout: /script STARTED[\s\S]*v\d+\./,
  trim: true,
});
Repository: nodejs/node
File: test/sea/test-build-sea-custom-argv0.js (JavaScript)

Code before:
'use strict';
// This tests --build-sea with a custom argv0 value.

require('../common');

const { skipIfBuildSEAIsNotSupported } = require('../common/sea');

skipIfBuildSEAIsNotSupported();

const tmpdir = require('../common/tmpdir');
const { resolve } = require('path');
const fixtures = require('../common/fixtures');
const { copyFileSync } = require('fs');

const { spawnSyncAndAssert } = require('../common/child_process');

const fixturesDir = fixtures.path('sea', 'basic');
const tempDir = tmpdir.path;

copyFileSync(
  resolve(fixturesDir, 'sea-config.json'),
  resolve(tempDir, 'sea-config.json'),
);

copyFileSync(
  resolve(fixturesDir, 'sea.js'),
  resolve(tempDir, 'sea.js'),
);

spawnSyncAndAssert(
  process.execPath,
  ['--build-sea', resolve(tempDir, 'sea-config.json')], {
    cwd: tempDir,
    argv0: 'argv0',
  }, {
    stdout: /Generated single executable/,
  });


Review comment (suggestion):
```suggestion
  fixtures.path('sea-config.json'),
  tmpdir.resolve('sea-config.json'),
```

Code after:
'use strict';
// This tests --build-sea with a custom argv0 value.

require('../common');

const { skipIfBuildSEAIsNotSupported } = require('../common/sea');

skipIfBuildSEAIsNotSupported();

const tmpdir = require('../common/tmpdir');
const fixtures = require('../common/fixtures');
const { copyFileSync } = require('fs');

const { spawnSyncAndAssert } = require('../common/child_process');
tmpdir.refresh();

copyFileSync(
  fixtures.path('sea', 'basic', 'sea-config.json'),
  tmpdir.resolve('sea-config.json'),
);

copyFileSync(
  fixtures.path('sea', 'basic', 'sea.js'),
  tmpdir.resolve('sea.js'),
);

spawnSyncAndAssert(
  process.execPath,
  ['--build-sea', tmpdir.resolve('sea-config.json')], {
    cwd: tmpdir.path,
    argv0: 'argv0',
  }, {
    stdout: /Generated single executable/,
  });
Repository: nodejs/node
File: test/sea/test-build-sea-custom-argv0.js (JavaScript)

Code before:
// This tests --build-sea with a custom argv0 value.

require('../common');

const { skipIfBuildSEAIsNotSupported } = require('../common/sea');

skipIfBuildSEAIsNotSupported();

const tmpdir = require('../common/tmpdir');
const { resolve } = require('path');
const fixtures = require('../common/fixtures');
const { copyFileSync } = require('fs');

const { spawnSyncAndAssert } = require('../common/child_process');

const fixturesDir = fixtures.path('sea', 'basic');
const tempDir = tmpdir.path;

copyFileSync(
  resolve(fixturesDir, 'sea-config.json'),
  resolve(tempDir, 'sea-config.json'),
);

copyFileSync(
  resolve(fixturesDir, 'sea.js'),
  resolve(tempDir, 'sea.js'),
);

spawnSyncAndAssert(
  process.execPath,
  ['--build-sea', resolve(tempDir, 'sea-config.json')], {
    cwd: tempDir,
    argv0: 'argv0',
  }, {
    stdout: /Generated single executable/,
  });


Review comment (suggestion):
```suggestion
  fixtures.path('sea.js'),
  tmpdir.resolve('sea.js'),
```

Code after:
// This tests --build-sea with a custom argv0 value.

require('../common');

const { skipIfBuildSEAIsNotSupported } = require('../common/sea');

skipIfBuildSEAIsNotSupported();

const tmpdir = require('../common/tmpdir');
const fixtures = require('../common/fixtures');
const { copyFileSync } = require('fs');

const { spawnSyncAndAssert } = require('../common/child_process');
tmpdir.refresh();

copyFileSync(
  fixtures.path('sea', 'basic', 'sea-config.json'),
  tmpdir.resolve('sea-config.json'),
);

copyFileSync(
  fixtures.path('sea', 'basic', 'sea.js'),
  tmpdir.resolve('sea.js'),
);

spawnSyncAndAssert(
  process.execPath,
  ['--build-sea', tmpdir.resolve('sea-config.json')], {
    cwd: tmpdir.path,
    argv0: 'argv0',
  }, {
    stdout: /Generated single executable/,
  });
Repository: nodejs/node
File: test/sea/test-build-sea-custom-argv0.js (JavaScript)

Code before:

skipIfBuildSEAIsNotSupported();

const tmpdir = require('../common/tmpdir');
const { resolve } = require('path');
const fixtures = require('../common/fixtures');
const { copyFileSync } = require('fs');

const { spawnSyncAndAssert } = require('../common/child_process');

const fixturesDir = fixtures.path('sea', 'basic');
const tempDir = tmpdir.path;

copyFileSync(
  resolve(fixturesDir, 'sea-config.json'),
  resolve(tempDir, 'sea-config.json'),
);

copyFileSync(
  resolve(fixturesDir, 'sea.js'),
  resolve(tempDir, 'sea.js'),
);

spawnSyncAndAssert(
  process.execPath,
  ['--build-sea', resolve(tempDir, 'sea-config.json')], {
    cwd: tempDir,
    argv0: 'argv0',
  }, {
    stdout: /Generated single executable/,
  });


Review comment (suggestion):
```suggestion
  ['--build-sea', tmpdir.resolve('sea-config.json')], {
```

Code after:

skipIfBuildSEAIsNotSupported();

const tmpdir = require('../common/tmpdir');
const fixtures = require('../common/fixtures');
const { copyFileSync } = require('fs');

const { spawnSyncAndAssert } = require('../common/child_process');
tmpdir.refresh();

copyFileSync(
  fixtures.path('sea', 'basic', 'sea-config.json'),
  tmpdir.resolve('sea-config.json'),
);

copyFileSync(
  fixtures.path('sea', 'basic', 'sea.js'),
  tmpdir.resolve('sea.js'),
);

spawnSyncAndAssert(
  process.execPath,
  ['--build-sea', tmpdir.resolve('sea-config.json')], {
    cwd: tmpdir.path,
    argv0: 'argv0',
  }, {
    stdout: /Generated single executable/,
  });
Repository: nodejs/node
File: test/sea/test-build-sea-custom-argv0.js (JavaScript)

Code before:
'use strict';
// This tests --build-sea with a custom argv0 value.

require('../common');

const { skipIfBuildSEAIsNotSupported } = require('../common/sea');

skipIfBuildSEAIsNotSupported();

const tmpdir = require('../common/tmpdir');
const fixtures = require('../common/fixtures');
const { copyFileSync } = require('fs');

const { spawnSyncAndAssert } = require('../common/child_process');
tmpdir.refresh();

copyFileSync(
  fixtures.path('sea-config.json'),
  tmpdir.resolve('sea-config.json'),
);

copyFileSync(
  fixtures.path('sea.js'),
  tmpdir.resolve('sea.js'),
);

spawnSyncAndAssert(
  process.execPath,
  ['--build-sea', tmpdir.resolve('sea-config.json')], {
    cwd: tmpdir.path,
    argv0: 'argv0',
  }, {
    stdout: /Generated single executable/,
  });


Review comment (suggestion):
```suggestion
  fixtures.path('sea', 'basic', sea-config.json'),
```


Code after:
'use strict';
// This tests --build-sea with a custom argv0 value.

require('../common');

const { skipIfBuildSEAIsNotSupported } = require('../common/sea');

skipIfBuildSEAIsNotSupported();

const tmpdir = require('../common/tmpdir');
const fixtures = require('../common/fixtures');
const { copyFileSync } = require('fs');

const { spawnSyncAndAssert } = require('../common/child_process');
tmpdir.refresh();

copyFileSync(
  fixtures.path('sea', 'basic', 'sea-config.json'),
  tmpdir.resolve('sea-config.json'),
);

copyFileSync(
  fixtures.path('sea', 'basic', 'sea.js'),
  tmpdir.resolve('sea.js'),
);

spawnSyncAndAssert(
  process.execPath,
  ['--build-sea', tmpdir.resolve('sea-config.json')], {
    cwd: tmpdir.path,
    argv0: 'argv0',
  }, {
    stdout: /Generated single executable/,
  });
Repository: nodejs/node
File: test/sea/test-build-sea-custom-argv0.js (JavaScript)

Code before:
'use strict';
// This tests --build-sea with a custom argv0 value.

require('../common');

const { skipIfBuildSEAIsNotSupported } = require('../common/sea');

skipIfBuildSEAIsNotSupported();

const tmpdir = require('../common/tmpdir');
const fixtures = require('../common/fixtures');
const { copyFileSync } = require('fs');

const { spawnSyncAndAssert } = require('../common/child_process');
tmpdir.refresh();

copyFileSync(
  fixtures.path('sea-config.json'),
  tmpdir.resolve('sea-config.json'),
);

copyFileSync(
  fixtures.path('sea.js'),
  tmpdir.resolve('sea.js'),
);

spawnSyncAndAssert(
  process.execPath,
  ['--build-sea', tmpdir.resolve('sea-config.json')], {
    cwd: tmpdir.path,
    argv0: 'argv0',
  }, {
    stdout: /Generated single executable/,
  });


Review comment (suggestion):
```suggestion
  fixtures.path('sea', 'basic', sea.js'),
```


Code after:
'use strict';
// This tests --build-sea with a custom argv0 value.

require('../common');

const { skipIfBuildSEAIsNotSupported } = require('../common/sea');

skipIfBuildSEAIsNotSupported();

const tmpdir = require('../common/tmpdir');
const fixtures = require('../common/fixtures');
const { copyFileSync } = require('fs');

const { spawnSyncAndAssert } = require('../common/child_process');
tmpdir.refresh();

copyFileSync(
  fixtures.path('sea', 'basic', 'sea-config.json'),
  tmpdir.resolve('sea-config.json'),
);

copyFileSync(
  fixtures.path('sea', 'basic', 'sea.js'),
  tmpdir.resolve('sea.js'),
);

spawnSyncAndAssert(
  process.execPath,
  ['--build-sea', tmpdir.resolve('sea-config.json')], {
    cwd: tmpdir.path,
    argv0: 'argv0',
  }, {
    stdout: /Generated single executable/,
  });