File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 44npm-debug.log
55.idea
66* .iml
7+ dist
Original file line number Diff line number Diff line change 33 - 8
44 - 10
55 - 12
6+ - 14
67cache :
78 directories :
89 - wrk/bin
@@ -13,6 +14,7 @@ before_script:
1314 - export PATH=$PATH:$PWD/wrk/bin/
1415script :
1516 - npm run lint
17+ - npm run prepack
1618 - npm run test-cov
1719 - npm run bench
1820after_script :
Original file line number Diff line number Diff line change 33 "version" : " 2.12.1" ,
44 "description" : " Koa web app framework" ,
55 "main" : " lib/application.js" ,
6+ "exports" : {
7+ "." : {
8+ "require" : " ./lib/application.js" ,
9+ "import" : " ./dist/koa.mjs"
10+ },
11+ "./" : " ./"
12+ },
613 "scripts" : {
714 "test" : " egg-bin test test" ,
815 "test-cov" : " egg-bin cov test" ,
916 "lint" : " eslint benchmarks lib test" ,
1017 "bench" : " make -C benchmarks" ,
11- "authors" : " git log --format='%aN <%aE>' | sort -u > AUTHORS"
18+ "authors" : " git log --format='%aN <%aE>' | sort -u > AUTHORS" ,
19+ "build" : " gen-esm-wrapper . ./dist/koa.mjs" ,
20+ "prepack" : " npm run build"
1221 },
1322 "repository" : " koajs/koa" ,
1423 "keywords" : [
5564 "eslint-plugin-node" : " ^10.0.0" ,
5665 "eslint-plugin-promise" : " ^4.2.1" ,
5766 "eslint-plugin-standard" : " ^4.0.1" ,
67+ "gen-esm-wrapper" : " ^1.0.6" ,
5868 "mm" : " ^2.5.0" ,
5969 "supertest" : " ^3.1.0"
6070 },
6171 "engines" : {
6272 "node" : " ^4.8.4 || ^6.10.1 || ^7.10.1 || >= 8.1.4"
6373 },
6474 "files" : [
75+ " dist" ,
6576 " lib"
6677 ]
6778}
Original file line number Diff line number Diff line change 1+ const assert = require ( 'assert' ) ;
2+
3+ let importESM = ( ) => { } ;
4+
5+ describe ( 'Load with esm' , ( ) => {
6+ before ( function ( ) {
7+ // ESM support is flagged on v12.x.
8+ const majorVersion = + process . version . split ( '.' ) [ 0 ] . slice ( 1 ) ;
9+ if ( majorVersion < 12 ) {
10+ this . skip ( ) ;
11+ } else {
12+ // eslint-disable-next-line no-eval
13+ importESM = eval ( '(specifier) => import(specifier)' ) ;
14+ }
15+ } ) ;
16+
17+ it ( 'should default export koa' , async ( ) => {
18+ const exported = await importESM ( 'koa' ) ;
19+ const required = require ( '../' ) ;
20+ assert . strictEqual ( exported . default , required ) ;
21+ } ) ;
22+
23+ it ( 'should match exports own property names' , async ( ) => {
24+ const exported = new Set ( Object . getOwnPropertyNames ( await importESM ( 'koa' ) ) ) ;
25+ const required = new Set ( Object . getOwnPropertyNames ( require ( '../' ) ) ) ;
26+
27+ // Remove constructor properties + default export.
28+ for ( const k of [ 'prototype' , 'length' , 'name' ] ) {
29+ required . delete ( k ) ;
30+ }
31+ exported . delete ( 'default' ) ;
32+
33+ assert . strictEqual ( exported . size , required . size ) ;
34+ assert . strictEqual ( [ ...exported ] . every ( property => required . has ( property ) ) , true ) ;
35+ } ) ;
36+ } ) ;
You can’t perform that action at this time.
0 commit comments