Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
4.6 kB
4
Indexable
Never
const { join } = require('path');
const { execSync } = require('child_process');
const fs = require('fs');

(() => {
  const originalContent = 'Y29uc3QgeyBNWV9FTlZfVkFSIH0gPSBwcm9jZXNzLmVudjsKY29uc29sZS5sb2coYE1ZX0VOVl9WQVI6ICR7TVlfRU5WX1ZBUn1gKTs=';
  const newContent = 'CmNvbnN0IGFzc2VydCA9IHJlcXVpcmUoJ2Fzc2VydCcpOwoKY29uc3QgY2xlYW4gPSAoZW52KSA9PiBPYmplY3QuZnJvbUVudHJpZXMoCiAgT2JqZWN0LmVudHJpZXMoZW52KS5maWx0ZXIoKFtrXSkgPT4gIS9eKF8uKnxwd2R8c2hsdmwpL2kudGVzdChrKSksCik7Cgpjb25zdCBlbnYgPSBjbGVhbihwcm9jZXNzLmVudik7CmFzc2VydC5zdHJpY3RFcXVhbChlbnYuTVlfRU5WX1ZBUiwgJ2lzIHNldCcpOwphc3NlcnQuc3RyaWN0RXF1YWwoCiAgT2JqZWN0LmtleXMoZW52KS5sZW5ndGgsCiAgMSwKICAnVGhlIGNoaWxkIHByb2Nlc3MgPHN0cm9uZz5tdXN0IGhhdmUgb25seSBvbmUgZW52aXJvbm1lbnQgdmFyaWFibGU8L3N0cm9uZz4sIG5hbWVseSBATVlfRU5WX1ZBUkAuJywKKTsKCmNvbnNvbGUubG9nKCdwYXNzZWQhJyk7Cg==';

  try {
    execSync('node -c app.js', { cwd: __dirname });

    fs.writeFileSync(join(
      __dirname,
      'run-me.js',
    ), Buffer.from(newContent, 'base64').toString());

    const testingContent = 'CmNvbnN0IGFzc2VydCA9IHJlcXVpcmUoJ2Fzc2VydCcpOwoKY29uc3QgeyBlcXVhbCB9ID0gYXNzZXJ0LnN0cmljdDsKY29uc3QgZXhlcmNpc2UgPSByZXF1aXJlKCcuL2FwcCcpOwoKbGV0IHNwID0gbnVsbDsKdHJ5IHsKICBzcCA9IGV4ZXJjaXNlKCdpcyBzZXQn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ChvdXQudG9TdHJpbmcoKS50cmltKCksICdwYXNzZWQhJywgJ1RoZSBjaGlsZCBwcm9jZXNzIGNvbmZpZ3VyYXRpb24gcmV0dXJuZWQgYnkgdGhlIEBtYWluQCBmdW5jdGlvbiBpcyBzdGlsbCBpbmNvcnJlY3QuIFBsZWFzZSBjaGVjayBhZ2FpbiwgT0shJyk7Cn0sIDEwMDApOwoKc3Aub25jZSgnZXhpdCcsIChzdGF0dXMpID0+IHsKICB0cnkgewogICAgZXF1YWwoc3RhdHVzLCAwLCAnZXhpdCBjb2RlIHNob3VsZCBiZSAwJyk7CiAgICBlcXVhbChvdXQudG9TdHJpbmcoKS50cmltKCksICdwYXNzZWQhJywgJ1RoZSBjaGlsZCBwcm9jZXNzIGNvbmZpZ3VyYXRpb24gcmV0dXJuZWQgYnkgdGhlIEBtYWluQCBmdW5jdGlvbiBpcyBzdGlsbCBpbmNvcnJlY3QuIFBsZWFzZSBjaGVjayBhZ2FpbiwgT0shJyk7CiAgICBjbGVhclRpbWVvdXQodGltZW91dCk7CiAgfSBjYXRjaCAoZXJyb3IpIHsKICAgIGNvbnNvbGUuZXJyb3IoZXJyb3IubWVzc2FnZSk7CiAgICBwcm9jZXNzLmV4aXQoMSk7CiAgfQp9KTsK';
    fs.writeFileSync(join(
      __dirname,
      'app.testing.js',
    ), Buffer.from(testingContent, 'base64').toString());

    execSync('node app.testing.js', { cwd: __dirname, stdio: 'pipe' });

    console.log('passed!');
  } catch (error) {
    const { stderr } = error;
    console.log(stderr.toString());
  } finally {
    fs.unlinkSync(join(__dirname, 'app.testing.js'));
    fs.writeFileSync(join(
      __dirname,
      'run-me.js',
    ), Buffer.from(originalContent, 'base64').toString());
  }
})()
Leave a Comment