Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/pull-reqeust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ jobs:
- name: Check CommonJS and ESM package imports
run: npm run test:package

- name: Run packed SDK end-to-end tests
run: npm run test:e2e

- name: Check AWS Lambda handler error redaction
if: matrix.node-version != '18.x'
working-directory: examples/aws-lambda
Expand Down
1 change: 1 addition & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const config = {
statements: 80,
},
},
testPathIgnorePatterns: ['/node_modules/', '<rootDir>/tests/e2e/'],
clearMocks: true,
collectCoverage: true,
coverageReporters: ['text', 'cobertura'],
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@
"prepare": "npm run build",
"build:docs": "typedoc --out docs",
"version": "npm run export-version && git add src/version.ts",
"test:package": "node scripts/testPackage.js && node scripts/testPackageTypes.js"
"test:package": "node scripts/testPackage.js && node scripts/testPackageTypes.js",
"test:e2e": "node scripts/testE2E.js",
"test:e2e:live": "node scripts/testLiveE2E.js"
},
"keywords": [
"email",
Expand Down
76 changes: 76 additions & 0 deletions scripts/testE2E.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
const fs = require('node:fs');
const os = require('node:os');
const path = require('node:path');
const { spawnSync } = require('node:child_process');

const root = path.join(__dirname, '..');
const npm = process.platform === 'win32' ? 'npm.cmd' : 'npm';

function run(command, args, options = {}) {
const result = spawnSync(command, args, {
cwd: root,
stdio: 'inherit',
...options,
});
if (result.error || result.status !== 0) {
throw new Error('End-to-end test command failed.');
}
return result.stdout;
}

const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'nylas-sdk-e2e-'));
try {
run(npm, ['run', 'build']);
const packed = JSON.parse(
run(
npm,
['pack', '--ignore-scripts', '--json', '--pack-destination', tempDir],
{ encoding: 'utf8', stdio: ['ignore', 'pipe', 'inherit'] }
)
);
const filename = packed[0]?.filename;
if (typeof filename !== 'string' || path.basename(filename) !== filename) {
throw new Error('Unable to locate the packed SDK artifact.');
}

const consumerDir = path.join(tempDir, 'consumer');
fs.mkdirSync(consumerDir);
fs.writeFileSync(
path.join(consumerDir, 'package.json'),
JSON.stringify({ name: 'nylas-e2e-consumer', private: true })
);
run(
npm,
[
'install',
'--ignore-scripts',
'--no-audit',
'--no-fund',
'--package-lock=false',
'--loglevel=error',
path.join(tempDir, filename),
],
{ cwd: consumerDir }
);

const testsDir = path.join(root, 'tests', 'e2e');
const tests = fs
.readdirSync(testsDir)
.filter((name) => name.endsWith('.test.cjs'))
.sort()
.map((name) => path.join(testsDir, name));
if (tests.length === 0) {
throw new Error('No end-to-end tests found.');
}
process.stdout.write(
`Running packed SDK end-to-end tests on ${process.version}\n`
);
run(process.execPath, ['--test', ...tests], {
env: { ...process.env, NYLAS_E2E_CONSUMER_DIR: consumerDir },
});
} catch {
console.error('Packed SDK end-to-end checks failed.');
process.exitCode = 1;
} finally {
fs.rmSync(tempDir, { recursive: true, force: true });
}
Loading
Loading