<commit_before>// This test verifies that:
//  - a running service will not prevent NodeJS to exit if there is no compilation in progress.
//  - the NodeJS process will continue running if there is a serve() active or a transform or build in progress.

const assert = require('assert')
const { fork } = require('child_process');

// The tests to run in the child process
async function tests() {
  const esbuild = require('./esbuild').installForTests()

  async function testTransform() {
    const t1 = await esbuild.transform(`1+2`)
    const t2 = await esbuild.transform(`1+3`)
    assert.strictEqual(t1.code, `1 + 2;\n`)
    assert.strictEqual(t2.code, `1 + 3;\n`)
  }

  async function testServe() {
    const server = await esbuild.serve({}, {})
    assert.strictEqual(server.host, '0.0.0.0')
    assert.strictEqual(typeof server.port, 'number')
    server.stop()
    await server.wait
  }

  async function testBuild() {
    const result = await esbuild.build({
      stdin: { contents: '1+2' },
      write: false,
      incremental: true,
    })
    assert.deepStrictEqual(result.outputFiles.length, 1);
    assert.deepStrictEqual(result.outputFiles[0].text, '1 + 2;\n');
    assert.deepStrictEqual(result.stop, void 0);

    const result2 = await result.rebuild()
    assert.deepStrictEqual(result2.outputFiles.length, 1);
    assert.deepStrictEqual(result2.outputFiles[0].text, '1 + 2;\n');

    const result3 = await result2.rebuild()
    assert.deepStrictEqual(result3.outputFiles.length, 1);
    assert.deepStrictEqual(result3.outputFiles[0].text, '1 + 2;\n');

    result2.rebuild.dispose()
  }

  async function testWatch() {
    const result = await esbuild.build({
      stdin: { contents: '1+2' },
      write: false,
      watch: true,
    })

    assert.deepStrictEqual(result.rebuild, void 0);
    assert.deepStrictEqual(result.outputFiles.length, 1);
    assert.deepStrictEqual(result.outputFiles[0].text, '1 + 2;\n');

    result.stop()
  }

  async function testWatchAndIncremental() {
    const result = await esbuild.build({
      stdin: { contents: '1+2' },
      write: false,
      incremental: true,
      watch: true,
    })

    assert.deepStrictEqual(result.outputFiles.length, 1);
    assert.deepStrictEqual(result.outputFiles[0].text, '1 + 2;\n');

    result.stop()
    result.rebuild.dispose()
  }

  await testTransform()
  await testServe()
  await testBuild()
  await testWatch()
}

// Called when this is the child process to run the tests.
function runTests() {
  process.exitCode = 1;
  tests().then(() => {
    process.exitCode = 0;
  }, (error) => {
    console.error('❌', error)
  });
}

// A child process need to be started to verify that a running service is not hanging node.
function startChildProcess() {
  const child = fork(__filename, ['__forked__'], { stdio: 'inherit', env: process.env });

  const timeout = setTimeout(() => {
    console.error('❌ node unref test timeout - child_process.unref() broken?')
    process.exit(1);
  }, 30 * 1000);

  child.on('error', (error) => {
    console.error('❌', error);
    process.exit(1);
  })

  child.on('exit', (code) => {
    clearTimeout(timeout);
    if (code) {
      console.error(`❌ node unref tests failed: child exited with code ${code}`)
      process.exit(1);
    } else {
      console.log(`✅ node unref tests passed`)
    }
  })
}
<commit_msg>increase node unref test timeout for slow vms<commit_after>// This test verifies that:
//  - a running service will not prevent NodeJS to exit if there is no compilation in progress.
//  - the NodeJS process will continue running if there is a serve() active or a transform or build in progress.

const assert = require('assert')
const { fork } = require('child_process');

// The tests to run in the child process
async function tests() {
  const esbuild = require('./esbuild').installForTests()

  async function testTransform() {
    const t1 = await esbuild.transform(`1+2`)
    const t2 = await esbuild.transform(`1+3`)
    assert.strictEqual(t1.code, `1 + 2;\n`)
    assert.strictEqual(t2.code, `1 + 3;\n`)
  }

  async function testServe() {
    const server = await esbuild.serve({}, {})
    assert.strictEqual(server.host, '0.0.0.0')
    assert.strictEqual(typeof server.port, 'number')
    server.stop()
    await server.wait
  }

  async function testBuild() {
    const result = await esbuild.build({
      stdin: { contents: '1+2' },
      write: false,
      incremental: true,
    })
    assert.deepStrictEqual(result.outputFiles.length, 1);
    assert.deepStrictEqual(result.outputFiles[0].text, '1 + 2;\n');
    assert.deepStrictEqual(result.stop, void 0);

    const result2 = await result.rebuild()
    assert.deepStrictEqual(result2.outputFiles.length, 1);
    assert.deepStrictEqual(result2.outputFiles[0].text, '1 + 2;\n');

    const result3 = await result2.rebuild()
    assert.deepStrictEqual(result3.outputFiles.length, 1);
    assert.deepStrictEqual(result3.outputFiles[0].text, '1 + 2;\n');

    result2.rebuild.dispose()
  }

  async function testWatch() {
    const result = await esbuild.build({
      stdin: { contents: '1+2' },
      write: false,
      watch: true,
    })

    assert.deepStrictEqual(result.rebuild, void 0);
    assert.deepStrictEqual(result.outputFiles.length, 1);
    assert.deepStrictEqual(result.outputFiles[0].text, '1 + 2;\n');

    result.stop()
  }

  async function testWatchAndIncremental() {
    const result = await esbuild.build({
      stdin: { contents: '1+2' },
      write: false,
      incremental: true,
      watch: true,
    })

    assert.deepStrictEqual(result.outputFiles.length, 1);
    assert.deepStrictEqual(result.outputFiles[0].text, '1 + 2;\n');

    result.stop()
    result.rebuild.dispose()
  }

  await testTransform()
  await testServe()
  await testBuild()
  await testWatch()
}

// Called when this is the child process to run the tests.
function runTests() {
  process.exitCode = 1;
  tests().then(() => {
    process.exitCode = 0;
  }, (error) => {
    console.error('❌', error)
  });
}

// A child process need to be started to verify that a running service is not hanging node.
function startChildProcess() {
  const child = fork(__filename, ['__forked__'], { stdio: 'inherit', env: process.env });

  const timeout = setTimeout(() => {
    console.error('❌ node unref test timeout - child_process.unref() broken?')
    process.exit(1);
  }, 5 * 60 * 1000);

  child.on('error', (error) => {
    console.error('❌', error);
    process.exit(1);
  })

  child.on('exit', (code) => {
    clearTimeout(timeout);
    if (code) {
      console.error(`❌ node unref tests failed: child exited with code ${code}`)
      process.exit(1);
    } else {
      console.log(`✅ node unref tests passed`)
    }
  })
}

{'fraction_non_alphanumeric': 0.1446978672985782, 'fraction_numerical': 0.018809241706161137, 'mean_word_length': 3.279467680608365, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6315648', 'n_tokens_mistral': 2219, 'n_tokens_neox': 2166, 'n_words': 558}